9 #include <sys/lunaix.h>
11 #define must_mount(src, target, fs, opts) \
14 if ((err = mount(src, target, fs, opts))) { \
15 syslog(2, "mount fs %s to %s failed (%d)\n", fs, target, errno); \
20 #define maybe_mount(src, target, fs, opts) \
23 if ((err = mount(src, target, fs, opts))) { \
24 syslog(2, "mount fs %s to %s failed (%d)\n", fs, target, errno); \
28 #define check(statement) \
31 if ((err = (statement)) < 0) { \
32 syslog(2, #statement " failed: %d", err); \
39 init_termios(int fd) {
42 check(tcgetattr(fd, &term));
44 term.c_lflag = ICANON | IEXTEN | ISIG | ECHO | ECHOE;
45 term.c_iflag = ICRNL | IGNBRK;
46 term.c_oflag = ONLCR | OPOST;
47 term.c_cflag = CREAD | CLOCAL | CS8 | CPARENB;
48 term.c_cc[VERASE] = 0x7f;
50 cfsetispeed(&term, B9600);
51 cfsetospeed(&term, B9600);
53 check(tcsetattr(fd, 0, &term));
58 const char* sh_argv[] = { "/bin/sh", 0 };
59 const char* sh_envp[] = { 0 };
62 main(int argc, const char** argv)
64 must_mount(NULL, "/dev", "devfs", 0);
65 must_mount(NULL, "/sys", "twifs", MNT_RO);
66 must_mount(NULL, "/task", "taskfs", MNT_RO);
68 int fd = check(open("/dev/tty", 0));
70 check(init_termios(fd));
76 if (!(pid = fork())) {
77 err = execve(sh_argv[0], sh_argv, sh_envp);
78 printf("fail to execute (%d)\n", errno);
82 waitpid(pid, &err, 0);
84 if (WEXITSTATUS(err)) {
85 printf("shell exit abnormally (%d)\n", err);
88 printf("init exiting\n");