cleanup init: inline 2 functions, style, remove ifdef
- Two functions (assign_signal_handler() and set_enviornment()) were
called once from init_main(); inline them.
(inittab_parsing() is also called once, but it's large and messy
enough that splitting it out seems to clarify things.)
- As mentioned before, the #ifdef VT_OPENQRY block did not seem to have any
logical behavior. I deleted that and TERM to "linux" not "vt102".
I note though that "linux" should probably be a platform-specific
variable, so Net/OpenBSD should get "wscons" and FreeBSD "syscons"
if we ever support building init there.
- casting "VAR=value" to char* isn't necessary, as far as I can tell.
- Change #include<> to #include <>.
Potential issues not addressed:
-panic if fork/vfork fails (not observed; expected from final_run()).
-possible panic on some embedded platforms (CONFIG_VT disabled?):
xprintf() means that failing to write messages will panic the kernel.
Thanks,
Isaac Dunham
diff --git a/toys/pending/init.c b/toys/pending/init.c
index facf3b5..caa9bba 100644
--- a/toys/pending/init.c
+++ b/toys/pending/init.c
@@ -17,8 +17,8 @@ config INIT
*/
#include "toys.h"
-#include<linux/vt.h>
-#include<sys/reboot.h>
+#include <linux/vt.h>
+#include <sys/reboot.h>
struct action_list_seed {
struct action_list_seed *next;
@@ -59,14 +59,7 @@ static void initialize_console(void)
dup2(fd,2);
}
}
- p = getenv("TERM");
-#ifdef VT_OPENQRY
- int terminal_no;
- if (ioctl(0, VT_OPENQRY, &terminal_no)) {
- if (!p || !strcmp(p,"linux")) putenv((char*)"TERM=vt102");
- } else
-#endif
- if (!p) putenv((char*)"TERM=linux");
+ if (!getenv("TERM")) putenv("TERM=linux");
}
static void set_sane_term(void)
@@ -91,14 +84,6 @@ static void set_sane_term(void)
tcsetattr(0, TCSANOW, &terminal);
}
-static void set_enviornment(void)
-{
- putenv((char*)"HOME=/");
- putenv((char*)"PATH=/sbin:/usr/sbin:/bin:/usr/bin");
- putenv((char*)"SHELL=/bin/sh");
- putenv((char*)"USER=root");
-}
-
static void add_new_action(uint8_t action,char *command,char *term)
{
struct action_list_seed *x,**y;
@@ -403,25 +388,6 @@ static void pause_handler(int sig_no)
caught_signal = signal_backup;
}
-static void assign_signal_handler(void)
-{
- struct sigaction sig_act;
- signal(SIGUSR1, halt_poweroff_reboot_handler);//halt
- signal(SIGUSR2, halt_poweroff_reboot_handler);//poweroff
- signal(SIGTERM, halt_poweroff_reboot_handler);//reboot
- signal(SIGQUIT, restart_init_handler);//restart init
- memset(&sig_act, 0, sizeof(sig_act));
- sigfillset(&sig_act.sa_mask);
- sigdelset(&sig_act.sa_mask, SIGCONT);
- sig_act.sa_handler = pause_handler;
- sigaction(SIGTSTP, &sig_act, NULL);
-
- memset(&sig_act, 0, sizeof(sig_act));
- sig_act.sa_handler = catch_signal;
- sigaction(SIGINT, &sig_act, NULL);
- sigaction(SIGHUP, &sig_act, NULL);
-}
-
static int check_if_pending_signals(void)
{
int signal_caught = 0;
@@ -435,6 +401,8 @@ static int check_if_pending_signals(void)
}
void init_main(void)
{
+ struct sigaction sig_act;
+
if (getpid() != 1) error_exit("Already running");
xprintf("Started init\n");
initialize_console();
@@ -443,9 +411,24 @@ void init_main(void)
if (chdir("/")) perror_exit("Can't cd to /");
setsid();
- set_enviornment();
+ putenv("HOME=/");
+ putenv("PATH=/sbin:/usr/sbin:/bin:/usr/bin");
+ putenv("SHELL=/bin/sh");
+ putenv("USER=root");
inittab_parsing();
- assign_signal_handler();
+ signal(SIGUSR1, halt_poweroff_reboot_handler);//halt
+ signal(SIGUSR2, halt_poweroff_reboot_handler);//poweroff
+ signal(SIGTERM, halt_poweroff_reboot_handler);//reboot
+ signal(SIGQUIT, restart_init_handler);//restart init
+ memset(&sig_act, 0, sizeof(sig_act));
+ sigfillset(&sig_act.sa_mask);
+ sigdelset(&sig_act.sa_mask, SIGCONT);
+ sig_act.sa_handler = pause_handler;
+ sigaction(SIGTSTP, &sig_act, NULL);
+ memset(&sig_act, 0, sizeof(sig_act));
+ sig_act.sa_handler = catch_signal;
+ sigaction(SIGINT, &sig_act, NULL);
+ sigaction(SIGHUP, &sig_act, NULL);
run_action_from_list(SYSINIT);
check_if_pending_signals();
run_action_from_list(WAIT);
_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net