3 #include <lunaix/lunaix.h>
4 #include <lunaix/mount.h>
9 #define must_mount(src, target, fs, opts) \
12 if ((err = mount(src, target, fs, opts))) { \
13 syslog(2, "mount fs %s to %s failed (%d)\n", fs, target, errno); \
18 #define maybe_mount(src, target, fs, opts) \
21 if ((err = mount(src, target, fs, opts))) { \
22 syslog(2, "mount fs %s to %s failed (%d)\n", fs, target, errno); \
26 #define check(statement) \
29 if ((err = (statement)) < 0) { \
30 syslog(2, #statement " failed: %d", err); \
37 init_termios(int fd) {
40 check(tcgetattr(fd, &term));
42 term.c_lflag = ICANON | IEXTEN | ISIG | ECHO | ECHOE;
43 term.c_iflag = ICRNL | IGNBRK;
44 term.c_oflag = ONLCR | OPOST;
45 term.c_cflag = CREAD | CLOCAL | CS8 | CPARENB;
46 term.c_cc[VERASE] = 0x7f;
48 cfsetispeed(&term, B9600);
49 cfsetospeed(&term, B9600);
51 check(tcsetattr(fd, 0, &term));
56 const char* sh_argv[] = { "/bin/sh", 0 };
57 const char* sh_envp[] = { 0 };
60 main(int argc, const char** argv)
62 must_mount(NULL, "/dev", "devfs", 0);
63 must_mount(NULL, "/sys", "twifs", MNT_RO);
64 must_mount(NULL, "/task", "taskfs", MNT_RO);
66 int fd = check(open("/dev/tty", 0));
68 check(init_termios(fd));
74 if (!(pid = fork())) {
75 err = execve(sh_argv[0], sh_argv, sh_envp);
76 printf("fail to execute (%d)\n", errno);
80 waitpid(pid, &err, 0);
82 if (WEXITSTATUS(err)) {
83 printf("shell exit abnormally (%d)\n", err);
86 printf("init exiting\n");