X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/db7fc030e9e04c881f5f12a0e23baa8db4e20ee1..f8bd95b7a13dfe54d800e2d7ecdb0329f0798289:/lunaix-os/uprog/init.c diff --git a/lunaix-os/uprog/init.c b/lunaix-os/uprog/init.c index a197245..82e3ea3 100644 --- a/lunaix-os/uprog/init.c +++ b/lunaix-os/uprog/init.c @@ -1,23 +1,39 @@ +#include #include +#include #include #include int main(int argc, const char** argv) { - int errno = 0; + int err = 0; - if ((errno = open("/dev/tty", 0))) { + if ((err = open("/dev/tty", 0)) < 0) { syslog(2, "fail to open tty (%d)\n", errno); return 0; } - if ((errno = dup(errno))) { + if ((err = dup(err)) < 0) { syslog(2, "fail to setup tty i/o (%d)\n", errno); return 0; } - syslog(0, "user space!\n"); + printf("(%p) user space!\n", (void*)main); + + if ((err = symlink("/usr", "/mnt/lunaix-os/usr"))) { + syslog(2, "symlink /usr:/mnt/lunaix-os/usr (%d)\n", errno); + return 0; + } + + pid_t pid; + if (!(pid = fork())) { + err = execve("/mnt/lunaix-os/usr/sh", NULL, NULL); + printf("fail to execute (%d)\n", errno); + _exit(err); + } + + waitpid(pid, NULL, 0); return 0; } \ No newline at end of file