summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-04-09 01:09:06 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-04-09 01:09:06 +0200
commit13b5e77a8be5f41f333e150d25f228d4a35ccbef (patch)
tree6e2be8efbd87a529756173088c3eb7a649aaa74b
parent3f9a100fae77a4886966cf41dd109be81055d3d0 (diff)
downloadminilinux-13b5e77a8be5f41f333e150d25f228d4a35ccbef.tar.gz
dhfhdkfl
-rwxr-xr-xclean.sh8
-rw-r--r--init/init.c97
2 files changed, 100 insertions, 5 deletions
diff --git a/clean.sh b/clean.sh
new file mode 100755
index 0000000..8789bf8
--- /dev/null
+++ b/clean.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+cd init
+make clean
+cd ../root
+rm -df *
+cd ..
+rm -df initramfs.cpio.gz
diff --git a/init/init.c b/init/init.c
index 00836b5..090dfe2 100644
--- a/init/init.c
+++ b/init/init.c
@@ -1,13 +1,100 @@
#include <stdio.h>
#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <poll.h>
-int main(int argc, char* argv[])
+int run_start(char* _prog)
+{
+ pid_t pid = fork();
+
+ if( pid < 0 )
+ return 1;
+ else if (pid == 0)
+ return 0;
+
+ execl(_prog, _prog, NULL);
+}
+
+int run_stdio(char* _prog)
{
- printf("I'm a kernel!\r\n");
+
+ int fork_pipe_out[2];
+ int fork_pipe_in [2];
+ pid_t pid = 0;
+
+ if(pipe(fork_pipe_out) == -1)
+ return 1;
+
+ if(pipe(fork_pipe_in) == -1)
+ return 1;
+
+ if((pid = fork()) == -1)
+ return 2;
+
+ if (pid == 0)
+ {
+ dup2(fork_pipe_out[1], STDOUT_FILENO);
+ dup2(fork_pipe_in [0], STDIN_FILENO );
+ close (fork_pipe_out[0]);
+ close (fork_pipe_in [1]);
+
+ execl(_prog, _prog, NULL);
- while(1)
+ return 3;
+ }
+ else
{
- printf("Still running!\r\n");
- sleep(1);
+ printf("asdf\n");
+ close(fork_pipe_out[1]);
+ close(fork_pipe_in [0]);
+
+ int ret;
+ struct pollfd fds[2];
+ fds[0].fd = STDIN_FILENO;
+ fds[0].events = POLLIN;
+
+ fds[1].fd = fork_pipe_out[0];
+ fds[1].events = POLLIN;
+
+ while(1)
+ {
+ int timeout = 1; //Timeout msecs
+ ret = poll(fds, 2, timeout);
+
+ if(ret < 0)
+ break;
+ else if (ret == 0)
+ continue;
+
+
+ int nbytes;
+ char buffer[256];
+
+ if(fds[0].revents & POLLIN) //STDIN_FILENO
+ {
+ printf("a\n");
+ nbytes = read(STDIN_FILENO, buffer, sizeof(buffer));
+ write(fork_pipe_in[1], buffer, nbytes);
+ write(fork_pipe_in[1], "\n", 1);
+
+ }
+ if(fds[1].revents & POLLIN) //PIPE
+ {
+ printf("b\”");
+ nbytes = read(fork_pipe_out[0], buffer, sizeof(buffer));
+ write(STDOUT_FILENO, buffer, nbytes);
+ write(STDOUT_FILENO, "\n", 1);
+ }
+ }
+ wait(0);
}
}
+
+int main(int argc, char* argv[])
+{
+ printf("MegumInit explosion!\n");
+ run_stdio("yes");
+
+ return 0;
+}