summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-04-09 19:20:23 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-04-09 19:20:23 +0200
commitbd7230debadfd090e7ccba20376e80611d239bd5 (patch)
tree7be66bf8df8180facf9db848c44ac6fcbeb0c1ec
parent13b5e77a8be5f41f333e150d25f228d4a35ccbef (diff)
downloadminilinux-bd7230debadfd090e7ccba20376e80611d239bd5.tar.gz
Stuff
-rw-r--r--.gitmodules3
-rwxr-xr-xclean.sh2
-rw-r--r--init/init.c79
m---------linux0
-rwxr-xr-xpackroot.sh7
-rwxr-xr-xstart.sh2
6 files changed, 73 insertions, 20 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..2902d5b
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "linux"]
+ path = linux
+ url = git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
diff --git a/clean.sh b/clean.sh
index 8789bf8..217c8c8 100755
--- a/clean.sh
+++ b/clean.sh
@@ -3,6 +3,6 @@
cd init
make clean
cd ../root
-rm -df *
+rm -df init
cd ..
rm -df initramfs.cpio.gz
diff --git a/init/init.c b/init/init.c
index 090dfe2..a87930b 100644
--- a/init/init.c
+++ b/init/init.c
@@ -1,27 +1,47 @@
#include <stdio.h>
+#include <errno.h>
+#include <string.h>
#include <unistd.h>
#include <stdlib.h>
+#include <stdarg.h>
#include <sys/types.h>
#include <poll.h>
-int run_start(char* _prog)
+#include <dirent.h>
+
+
+//Needs NULL as last arg!!
+int run_start(char* _prog, char* _args[])
{
pid_t pid = fork();
if( pid < 0 )
return 1;
else if (pid == 0)
+ {
+ //wait(0);
return 0;
+ }
+
+ setsid();
+ if(fork())
+ exit(0);
+
+ close(STDOUT_FILENO);
+ close(STDIN_FILENO);
+ close(STDERR_FILENO);
- execl(_prog, _prog, NULL);
+ execv(_prog, _args);
+
+ exit(1);
}
-int run_stdio(char* _prog)
-{
-
+//Need NULL as last arg!!
+int run_stdio(char* _prog, const char* _args[])
+{
int fork_pipe_out[2];
int fork_pipe_in [2];
- pid_t pid = 0;
+ pid_t pid;
if(pipe(fork_pipe_out) == -1)
return 1;
@@ -34,18 +54,22 @@ int run_stdio(char* _prog)
if (pid == 0)
{
+ //replace STDIO
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);
- return 3;
+ execv(_prog, _args);
+
+ //Error handling
+ int err = errno;
+ printf("Fuckup %i: %s\n", err, strerror(err));
+
+ exit(1);
}
else
{
- printf("asdf\n");
close(fork_pipe_out[1]);
close(fork_pipe_in [0]);
@@ -57,7 +81,7 @@ int run_stdio(char* _prog)
fds[1].fd = fork_pipe_out[0];
fds[1].events = POLLIN;
- while(1)
+ while(1)//Check for data while pipe is open
{
int timeout = 1; //Timeout msecs
ret = poll(fds, 2, timeout);
@@ -73,28 +97,51 @@ int run_stdio(char* _prog)
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);
+ //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);
+ //write(STDOUT_FILENO, "\n", 1);
}
}
wait(0);
}
}
+int exists(const char *fname)
+{
+ FILE *file;
+ if ((file = fopen(fname, "r")))
+ {
+ fclose(file);
+ return 1;
+ }
+ return 0;
+}
+
int main(int argc, char* argv[])
{
printf("MegumInit explosion!\n");
- run_stdio("yes");
+
+ //char* arg[] = {"/bin/bash" ,(char*)0};
+
+ //run_start(arg[0], arg);
+
+ char* arg2[] = {"/bin/toybox", "echo", "/test.asdf", NULL};
+
+ run_start(arg2[0], arg2);
+
+ sleep(2);
+
+ printf("%i\n", exists("/test.asdf"));
+ printf("\nEND\n");
+
+ sleep(99999);
return 0;
}
diff --git a/linux b/linux
new file mode 160000
+Subproject 79a3aaa7b82e3106be97842dedfd8429248896e
diff --git a/packroot.sh b/packroot.sh
index b9a6572..2447128 100755
--- a/packroot.sh
+++ b/packroot.sh
@@ -1,5 +1,8 @@
#!/bin/bash
-cd root
-find . -print -depth | cpio -ov -H newc > ../initramfs.cpio.gz
+cd init
+make build copy
+cd ..
+cd root
+find . | cpio -o -H newc | gzip > ../initramfs.cpio.gz
diff --git a/start.sh b/start.sh
index f26c99b..51b0d2a 100755
--- a/start.sh
+++ b/start.sh
@@ -1,4 +1,4 @@
#!/bin/bash
-screen qemu-system-x86_64 -nographic -no-reboot -kernel bzImage -initrd initramfs.cpio.gz -m 256M -append "console=ttyS0 panic=1"
+screen qemu-system-x86_64 -nographic -no-reboot -kernel bzImage -initrd initramfs.cpio.gz -m 256M -append "console=ttyS0 panic=20"