diff options
author | Isaac Dunham <ibid.ag@gmail.com> | 2014-04-12 17:26:44 -0500 |
---|---|---|
committer | Isaac Dunham <ibid.ag@gmail.com> | 2014-04-12 17:26:44 -0500 |
commit | 931425ca05b93348dd497598af077d16cdc1cd3c (patch) | |
tree | 1c5d8a9c9cf0d9953b8d74077b762e1d87b6fdf0 /toys/pending/init.c | |
parent | 669f332aafe1afdbbfbe4b7c1c8fdab6fa2cec1d (diff) | |
download | toybox-931425ca05b93348dd497598af077d16cdc1cd3c.tar.gz |
roadmap: describe glibc commands.
Some glibc commands are irrelevant because they're for functionality
that is excluded from musl (mtrace, rpc*, localedef, iconvconfig, nscd).
getconf and catchsegv look like candidates for the development toolchain;
locale and iconv were already triaged.
getent is pretty lame, but it and the timezone stuff (tzselect zic
zdump) are the only new possibly interesting commands.
Diffstat (limited to 'toys/pending/init.c')
-rw-r--r-- | toys/pending/init.c | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/toys/pending/init.c b/toys/pending/init.c index 8199e748..ca3c6cc4 100644 --- a/toys/pending/init.c +++ b/toys/pending/init.c @@ -13,7 +13,10 @@ config INIT help usage: init - init the system. + System V style init. + + First program to run (as PID 1) when the system comes up, reading + /etc/inittab to determine actions. */ #include "toys.h" @@ -41,8 +44,9 @@ int caught_signal; static void initialize_console(void) { int fd; - char *p = (p = getenv("CONSOLE")) ? p : getenv("console"); + char *p = getenv("CONSOLE"); + if (!p) p = getenv("console"); if (!p) { fd = open("/dev/null", O_RDWR); if (fd >= 0) { @@ -62,11 +66,11 @@ static void initialize_console(void) if (!getenv("TERM")) putenv("TERM=linux"); } -static void set_sane_term(void) +static void reset_term(int fd) { struct termios terminal; - tcgetattr(0, &terminal); + tcgetattr(fd, &terminal); terminal.c_cc[VINTR] = 3; //ctrl-c terminal.c_cc[VQUIT] = 28; /*ctrl-\*/ terminal.c_cc[VERASE] = 127; //ctrl-? @@ -77,12 +81,16 @@ static void set_sane_term(void) terminal.c_cc[VSUSP] = 26; //ctrl-z terminal.c_line = 0; - terminal.c_cflag = terminal.c_cflag&(CRTSCTS|PARODD|PARENB|CSTOPB|CSIZE|CBAUDEX|CBAUD); - terminal.c_cflag = terminal.c_cflag|(CLOCAL|HUPCL|CREAD); - terminal.c_iflag = IXON|IXOFF|ICRNL;//enable start/stop input and output control + map CR to NL on input - terminal.c_oflag = ONLCR|OPOST;//Map NL to CR-NL on output + terminal.c_cflag &= CRTSCTS|PARODD|PARENB|CSTOPB|CSIZE|CBAUDEX|CBAUD; + terminal.c_cflag |= CLOCAL|HUPCL|CREAD; + + //enable start/stop input and output control + map CR to NL on input + terminal.c_iflag = IXON|IXOFF|ICRNL; + + //Map NL to CR-NL on output + terminal.c_oflag = ONLCR|OPOST; terminal.c_lflag = IEXTEN|ECHOKE|ECHOCTL|ECHOK|ECHOE|ECHO|ICANON|ISIG; - tcsetattr(0, TCSANOW, &terminal); + tcsetattr(fd, TCSANOW, &terminal); } static void add_new_action(uint8_t action,char *command,char *term) @@ -250,7 +258,7 @@ static pid_t final_run(struct action_list_seed *x) dup2(0, 2); } } - set_sane_term(); + reset_term(0); run_command(x->command); _exit(-1); } @@ -281,6 +289,7 @@ static void waitforpid(pid_t pid) if (kill(y, 0)) break; } } + static void run_action_from_list(int action) { pid_t pid; @@ -302,14 +311,7 @@ static void set_default(void) { sigset_t signal_set_c; - signal(SIGUSR1,SIG_DFL); - signal(SIGUSR2,SIG_DFL); - signal(SIGTERM,SIG_DFL); - signal(SIGQUIT,SIG_DFL); - signal(SIGINT,SIG_DFL); - signal(SIGHUP,SIG_DFL); - signal(SIGTSTP,SIG_DFL); - signal(SIGSTOP,SIG_DFL); + sigatexit(SIG_DFL); sigfillset(&signal_set_c); sigprocmask(SIG_UNBLOCK,&signal_set_c, NULL); @@ -357,6 +359,7 @@ static void halt_poweroff_reboot_handler(int sig_no) while(1) sleep(1); } + static void restart_init_handler(int sig_no) { struct action_list_seed *x; @@ -386,7 +389,7 @@ static void restart_init_handler(int sig_no) } else { dup2(0, 1); dup2(0, 2); - set_sane_term(); + reset_term(0); run_command(x->command); } } @@ -440,7 +443,7 @@ void init_main(void) if (getpid() != 1) error_exit("Already running"); printf("Started init\n"); initialize_console(); - set_sane_term(); + reset_term(0); if (chdir("/")) perror_exit("Can't cd to /"); setsid(); @@ -449,6 +452,7 @@ void init_main(void) putenv("PATH=/sbin:/usr/sbin:/bin:/usr/bin"); putenv("SHELL=/bin/sh"); putenv("USER=root"); + inittab_parsing(); signal(SIGUSR1, halt_poweroff_reboot_handler);//halt signal(SIGUSR2, halt_poweroff_reboot_handler);//poweroff |