/* Simply C program to act as init. */ #include #include #include #include #include #include #include #include #include #include #include #include #include static int wait_for(const char *prog) { int status; wait(&status); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { fprintf(stderr, "run: %s failed\n", prog); return 0; } return 1; } int main(int argc, char *argv[]) { if (fork() == 0) { execl("/ifconfig", "ifconfig", "eth0", "192.168.1.2", NULL); fprintf(stderr, "run: ifconfig exec failed\n"); exit(1); } if (!wait_for("ifconfig")) goto reboot; if (fork() == 0) { execl("/route", "route", "add", "default", "gw", "192.168.1.1", NULL); fprintf(stderr, "run: route exec failed\n"); exit(1); } if (!wait_for("route")) goto reboot; /* tetrinet does DNS lookup on own hostname */ sethostname("ozlabs.org", strlen("ozlabs.org")); if (fork() == 0) { setgroups(0, NULL); /* Games/games */ setgid(60); setuid(5); close(0); close(1); close(2); open("/dev/null", O_RDWR); open("/dev/null", O_RDWR); open("/dev/null", O_RDWR); execl("/tetrinetx", "tetrinetx", NULL); exit(1); } if (!wait_for("tetrinetx")) goto reboot; /* Drop privs, why not? */ setgroups(0, NULL); setgid(65534); setuid(65534); close(0); close(1); close(2); while (wait(NULL) >= 0); reboot: sync(); reboot(LINUX_REBOOT_CMD_RESTART); sleep(60); return 1; }