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 check(statement) \
21 if ((err = (statement))) { \
22 syslog(2, #statement " failed: %d", err); \
28 init_termios(int fd) {
31 check(tcgetattr(fd, &term));
33 term.c_lflag = ICANON | IEXTEN | ISIG | ECHO | ECHOE | ECHONL;
34 term.c_iflag = ICRNL | IGNBRK;
35 term.c_oflag = ONLCR | OPOST;
36 term.c_cflag = CREAD | CLOCAL | CS8 | CPARENB;
37 term.c_cc[VERASE] = 0x08;
39 check(tcsetattr(fd, 0, &term));
45 main(int argc, const char** argv)
53 must_mount(NULL, "/dev", "devfs", 0);
54 must_mount(NULL, "/sys", "twifs", MNT_RO);
55 must_mount(NULL, "/task", "taskfs", MNT_RO);
57 if ((err = open("/dev/tty", 0)) < 0) {
58 syslog(2, "fail to open tty (%d)\n", errno);
62 check(init_termios(err));
64 if ((err = dup(err)) < 0) {
65 syslog(2, "fail to setup tty i/o (%d)\n", errno);
69 if ((err = symlink("/usr", "/mnt/lunaix-os/usr"))) {
70 syslog(2, "symlink /usr:/mnt/lunaix-os/usr (%d)\n", errno);
75 if (!(pid = fork())) {
76 err = execve("/usr/bin/sh", NULL, NULL);
77 printf("fail to execute (%d)\n", errno);
81 waitpid(pid, &err, 0);
83 if (WEXITSTATUS(err)) {
84 printf("shell exit abnormally (%d)", err);