From 730e4d8b5245502803c9c2335e96d81f70d63012 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 12 Oct 2013 04:52:22 +0200 Subject: init: better --help text Signed-off-by: Denys Vlasenko --- init/init.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'init') diff --git a/init/init.c b/init/init.c index edb5be696..cc6a2b5be 100644 --- a/init/init.c +++ b/init/init.c @@ -9,11 +9,6 @@ * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ -//applet:IF_INIT(APPLET(init, BB_DIR_SBIN, BB_SUID_DROP)) -//applet:IF_FEATURE_INITRD(APPLET_ODDNAME(linuxrc, init, BB_DIR_ROOT, BB_SUID_DROP, linuxrc)) - -//kbuild:lib-$(CONFIG_INIT) += init.o - //config:config INIT //config: bool "init" //config: default y @@ -108,6 +103,11 @@ //config: Note that on Linux, init attempts to detect serial terminal and //config: sets TERM to "vt102" if one is found. +//applet:IF_INIT(APPLET(init, BB_DIR_SBIN, BB_SUID_DROP)) +//applet:IF_FEATURE_INITRD(APPLET_ODDNAME(linuxrc, init, BB_DIR_ROOT, BB_SUID_DROP, linuxrc)) + +//kbuild:lib-$(CONFIG_INIT) += init.o + #define DEBUG_SEGV_HANDLER 0 #include "libbb.h" @@ -1230,7 +1230,14 @@ int init_main(int argc UNUSED_PARAM, char **argv) //usage:#define init_trivial_usage //usage: "" //usage:#define init_full_usage "\n\n" -//usage: "Init is the parent of all processes" +//usage: "Init is the first process started during boot. It never exits." +//usage: IF_FEATURE_USE_INITTAB( +//usage: "\n""It (re)spawns children according to /etc/inittab." +//usage: ) +//usage: IF_NOT_FEATURE_USE_INITTAB( +//usage: "\n""This version of init doesn't use /etc/inittab," +//usage: "\n""has fixed set of processed to run." +//usage: ) //usage: //usage:#define init_notes_usage //usage: "This version of init is designed to be run only by the kernel.\n" -- cgit v1.2.3-55-g6feb From 18b461925c6297f241c2b51f96f5d6d5f5de9e1d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 3 Nov 2013 00:07:31 +0100 Subject: bootchartd: warn if .config looks wrong Signed-off-by: Denys Vlasenko --- init/bootchartd.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'init') diff --git a/init/bootchartd.c b/init/bootchartd.c index 9fd623357..c7388c99e 100644 --- a/init/bootchartd.c +++ b/init/bootchartd.c @@ -60,6 +60,12 @@ # endif #endif +#if !ENABLE_TAR && !ENABLE_WERROR +# warning Note: bootchartd requires tar command, but you did not select it. +#elif !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_WERROR +# warning Note: bootchartd requires tar -z support, but you did not select it. +#endif + #define BC_VERSION_STR "0.8" /* For debugging, set to 0: -- cgit v1.2.3-55-g6feb From b21bc80c7651bfb5a9e001cc220a598cf89b7cfd Mon Sep 17 00:00:00 2001 From: Yuan-Hsiang Lee Date: Sun, 3 Nov 2013 00:13:16 +0100 Subject: init: fix illegal memory access when max message length is reached Signed-off-by: Yuan-Hsiang Lee Signed-off-by: Denys Vlasenko --- init/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'init') diff --git a/init/init.c b/init/init.c index cc6a2b5be..2dcdfd471 100644 --- a/init/init.c +++ b/init/init.c @@ -222,8 +222,8 @@ static void message(int where, const char *fmt, ...) msg[0] = '\r'; va_start(arguments, fmt); l = 1 + vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments); - if (l > sizeof(msg) - 1) - l = sizeof(msg) - 1; + if (l > sizeof(msg) - 2) + l = sizeof(msg) - 2; va_end(arguments); #if ENABLE_FEATURE_INIT_SYSLOG -- cgit v1.2.3-55-g6feb From 8b59b2c13ededb2c82e36193b6d6e969df36531c Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 19 Nov 2013 13:36:45 +0100 Subject: libbb: move nuke_str() from passwd into libbb function old new delta nuke_str - 15 +15 ask_and_check_password_extended 215 206 -9 init_main 781 771 -10 nuke_str 27 - -27 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/2 up/down: 15/-46) Total: -31 bytes Signed-off-by: Denys Vlasenko --- include/libbb.h | 7 ++++--- init/init.c | 2 +- libbb/correct_password.c | 11 ++++++++++- loginutils/passwd.c | 5 ----- 4 files changed, 15 insertions(+), 10 deletions(-) (limited to 'init') diff --git a/include/libbb.h b/include/libbb.h index e99bb928f..64167bba3 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1300,9 +1300,10 @@ int sd_listen_fds(void); #define SETUP_ENV_CLEARENV (1 << 1) #define SETUP_ENV_TO_TMP (1 << 2) #define SETUP_ENV_NO_CHDIR (1 << 4) -extern void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; -extern int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC; -extern int ask_and_check_password(const struct passwd *pw) FAST_FUNC; +void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; +void nuke_str(char *str) FAST_FUNC; +int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC; +int ask_and_check_password(const struct passwd *pw) FAST_FUNC; /* Returns a malloced string */ #if !ENABLE_USE_BB_CRYPT #define pw_encrypt(clear, salt, cleanup) pw_encrypt(clear, salt) diff --git a/init/init.c b/init/init.c index 2dcdfd471..c63bba1ff 100644 --- a/init/init.c +++ b/init/init.c @@ -1128,7 +1128,7 @@ int init_main(int argc UNUSED_PARAM, char **argv) strncpy(argv[0], "init", strlen(argv[0])); /* Wipe argv[1]-argv[N] so they don't clutter the ps listing */ while (*++argv) - memset(*argv, 0, strlen(*argv)); + nuke_str(*argv); /* Set up signal handlers */ if (!DEBUG_INIT) { diff --git a/libbb/correct_password.c b/libbb/correct_password.c index d39a5839c..5727c65fb 100644 --- a/libbb/correct_password.c +++ b/libbb/correct_password.c @@ -30,6 +30,15 @@ #include "libbb.h" +void FAST_FUNC nuke_str(char *str) +{ + if (str) { + while (*str) + *str++ = 0; + /* or: memset(str, 0, strlen(str)); - not as small as above */ + } +} + /* Ask the user for a password. * Return 1 without asking if PW has an empty password. * Return -1 on EOF, error while reading input, or timeout. @@ -76,7 +85,7 @@ int FAST_FUNC ask_and_check_password_extended(const struct passwd *pw, encrypted = pw_encrypt(unencrypted, correct, 1); r = (strcmp(encrypted, correct) == 0); free(encrypted); - memset(unencrypted, 0, strlen(unencrypted)); + nuke_str(unencrypted); return r; } diff --git a/loginutils/passwd.c b/loginutils/passwd.c index a7006f054..150908932 100644 --- a/loginutils/passwd.c +++ b/loginutils/passwd.c @@ -17,11 +17,6 @@ #include #include /* setrlimit */ -static void nuke_str(char *str) -{ - if (str) memset(str, 0, strlen(str)); -} - static char* new_password(const struct passwd *pw, uid_t myuid, const char *algo) { char salt[MAX_PW_SALT_LEN]; -- cgit v1.2.3-55-g6feb From 760fc6debcba8cb5ca8d8e2252fac3757c453e11 Mon Sep 17 00:00:00 2001 From: Bogdan Purcareata Date: Tue, 26 Nov 2013 13:54:48 +0100 Subject: init: halt on SIGPWR too Most init processes implement a handler for SIGPWR that gracefully stops all child processes when shutting down a machine. Some other technologies rely on this signal - e.g. Busybox powered LXC containers. This patch makes busybox init halt when receiving SIGPWR. Signed-off-by: Bogdan Purcareata Signed-off-by: Denys Vlasenko --- init/init.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'init') diff --git a/init/init.c b/init/init.c index c63bba1ff..d29328c36 100644 --- a/init/init.c +++ b/init/init.c @@ -789,7 +789,7 @@ static void run_shutdown_and_kill_processes(void) * and only one will be remembered and acted upon. */ -/* The SIGUSR[12]/SIGTERM handler */ +/* The SIGPWR/SIGUSR[12]/SIGTERM handler */ static void halt_reboot_pwoff(int sig) NORETURN; static void halt_reboot_pwoff(int sig) { @@ -1103,8 +1103,8 @@ int init_main(int argc UNUSED_PARAM, char **argv) /* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined, * then parse_inittab() simply adds in some default - * actions(i.e., INIT_SCRIPT and a pair - * of "askfirst" shells */ + * actions (i.e., INIT_SCRIPT and a pair + * of "askfirst" shells) */ parse_inittab(); } @@ -1135,6 +1135,7 @@ int init_main(int argc UNUSED_PARAM, char **argv) struct sigaction sa; bb_signals(0 + + (1 << SIGPWR) /* halt */ + (1 << SIGUSR1) /* halt */ + (1 << SIGTERM) /* reboot */ + (1 << SIGUSR2) /* poweroff */ -- cgit v1.2.3-55-g6feb