Merge branch 'master' into prog-loader
[lunaix-os.git] / lunaix-os / uprog / init.c
1 #include <fcntl.h>
2 #include <stdio.h>
3 #include <sys/lunaix.h>
4 #include <unistd.h>
5
6 int
7 main(int argc, const char** argv)
8 {
9     int errno = 0;
10
11     if ((errno = open("/dev/tty", 0)) < 0) {
12         syslog(2, "fail to open tty (%d)\n", errno);
13         return 0;
14     }
15
16     if ((errno = dup(errno)) < 0) {
17         syslog(2, "fail to setup tty i/o (%d)\n", errno);
18         return 0;
19     }
20
21     printf("(%p) user space!\n", (void*)main);
22
23     pid_t pid;
24     if (!(pid = fork())) {
25         int err = execve("/mnt/lunaix-os/usr/ls", NULL, NULL);
26         printf("fail to execute (%d)\n", err);
27         _exit(err);
28     }
29
30     waitpid(pid, NULL, 0);
31
32     return 0;
33 }