aboutsummaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-01-29 02:01:04 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-01-29 02:01:04 +0000
commit6c62246a3598efd3d1e9264f8d9f44d8d93a6453 (patch)
tree6a9959bea793c8afc9db08883cebb3bf621714cc /init
parentb2b2c404b5f2d67adfddc16e8f224e6ab5a7d18f (diff)
downloadbusybox-w32-6c62246a3598efd3d1e9264f8d9f44d8d93a6453.tar.gz
busybox-w32-6c62246a3598efd3d1e9264f8d9f44d8d93a6453.tar.bz2
busybox-w32-6c62246a3598efd3d1e9264f8d9f44d8d93a6453.zip
init: reinstate proper handling of !ENABLE_FEATURE_USE_INITTAB
Diffstat (limited to 'init')
-rw-r--r--init/init.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/init/init.c b/init/init.c
index 6ff9953b8..cea30c99f 100644
--- a/init/init.c
+++ b/init/init.c
@@ -13,25 +13,15 @@
13#include <syslog.h> 13#include <syslog.h>
14#include <paths.h> 14#include <paths.h>
15#include <sys/reboot.h> 15#include <sys/reboot.h>
16#include <sys/resource.h>
16 17
17/* Was a CONFIG_xxx option. A lot of people were building 18/* Was a CONFIG_xxx option. A lot of people were building
18 * not fully functional init by switching it on! */ 19 * not fully functional init by switching it on! */
19#define DEBUG_INIT 0 20#define DEBUG_INIT 0
20 21
21#define COMMAND_SIZE 256 22#define COMMAND_SIZE 256
22#define CONSOLE_NAME_SIZE 32 23#define CONSOLE_NAME_SIZE 32
23#define MAXENV 16 /* Number of env. vars */
24 24
25/*
26 * When a file named CORE_ENABLE_FLAG_FILE exists, setrlimit is called
27 * before processes are spawned to set core file size as unlimited.
28 * This is for debugging only. Don't use this is production, unless
29 * you want core dumps lying about....
30 */
31#define CORE_ENABLE_FLAG_FILE "/.init_enable_core"
32#include <sys/resource.h>
33
34#define INITTAB "/etc/inittab" /* inittab file location */
35#ifndef INIT_SCRIPT 25#ifndef INIT_SCRIPT
36#define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */ 26#define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */
37#endif 27#endif
@@ -56,7 +46,6 @@ struct init_action {
56 char command[COMMAND_SIZE]; 46 char command[COMMAND_SIZE];
57}; 47};
58 48
59/* Static variables */
60static struct init_action *init_action_list = NULL; 49static struct init_action *init_action_list = NULL;
61 50
62static const char *log_console = VC_5; 51static const char *log_console = VC_5;
@@ -74,7 +63,6 @@ enum {
74#endif 63#endif
75}; 64};
76 65
77/* Function prototypes */
78static void halt_reboot_pwoff(int sig) NORETURN; 66static void halt_reboot_pwoff(int sig) NORETURN;
79 67
80static void waitfor(pid_t pid) 68static void waitfor(pid_t pid)
@@ -445,9 +433,14 @@ static pid_t run(const struct init_action *a)
445 continue; 433 continue;
446 } 434 }
447 435
436 /*
437 * When a file named /.init_enable_core exists, setrlimit is called
438 * before processes are spawned to set core file size as unlimited.
439 * This is for debugging only. Don't use this is production, unless
440 * you want core dumps lying about....
441 */
448 if (ENABLE_FEATURE_INIT_COREDUMPS) { 442 if (ENABLE_FEATURE_INIT_COREDUMPS) {
449 struct stat sb; 443 if (access("/.init_enable_core", F_OK) == 0) {
450 if (stat(CORE_ENABLE_FLAG_FILE, &sb) == 0) {
451 struct rlimit limit; 444 struct rlimit limit;
452 limit.rlim_cur = RLIM_INFINITY; 445 limit.rlim_cur = RLIM_INFINITY;
453 limit.rlim_max = RLIM_INFINITY; 446 limit.rlim_max = RLIM_INFINITY;
@@ -665,15 +658,14 @@ static void new_init_action(uint8_t action_type, const char *command, const char
665 */ 658 */
666static void parse_inittab(void) 659static void parse_inittab(void)
667{ 660{
661#if ENABLE_FEATURE_USE_INITTAB
668 char *token[4]; 662 char *token[4];
669 /* order must correspond to SYSINIT..RESTART constants */ 663 parser_t *parser = config_open2("/etc/inittab", fopen_for_read);
670 static const char actions[] ALIGN1 = 664
671 "sysinit\0""respawn\0""askfirst\0""wait\0""once\0" 665 if (parser == NULL)
672 "ctrlaltdel\0""shutdown\0""restart\0"; 666#endif
673 667 {
674 parser_t *parser = config_open2(INITTAB, fopen_for_read); 668 /* No inittab file -- set up some default behavior */
675 /* No inittab file -- set up some default behavior */
676 if (parser == NULL) {
677 /* Reboot on Ctrl-Alt-Del */ 669 /* Reboot on Ctrl-Alt-Del */
678 new_init_action(CTRLALTDEL, "reboot", ""); 670 new_init_action(CTRLALTDEL, "reboot", "");
679 /* Umount all filesystems on halt/reboot */ 671 /* Umount all filesystems on halt/reboot */
@@ -693,11 +685,17 @@ static void parse_inittab(void)
693 new_init_action(SYSINIT, INIT_SCRIPT, ""); 685 new_init_action(SYSINIT, INIT_SCRIPT, "");
694 return; 686 return;
695 } 687 }
688
689#if ENABLE_FEATURE_USE_INITTAB
696 /* optional_tty:ignored_runlevel:action:command 690 /* optional_tty:ignored_runlevel:action:command
697 * Delims are not to be collapsed and need exactly 4 tokens 691 * Delims are not to be collapsed and need exactly 4 tokens
698 */ 692 */
699 while (config_read(parser, token, 4, 0, "#:", 693 while (config_read(parser, token, 4, 0, "#:",
700 PARSE_NORMAL & ~(PARSE_TRIM | PARSE_COLLAPSE))) { 694 PARSE_NORMAL & ~(PARSE_TRIM | PARSE_COLLAPSE))) {
695 /* order must correspond to SYSINIT..RESTART constants */
696 static const char actions[] ALIGN1 =
697 "sysinit\0""respawn\0""askfirst\0""wait\0""once\0"
698 "ctrlaltdel\0""shutdown\0""restart\0";
701 int action; 699 int action;
702 char *tty = token[0]; 700 char *tty = token[0];
703 701
@@ -721,6 +719,7 @@ static void parse_inittab(void)
721 parser->lineno); 719 parser->lineno);
722 } 720 }
723 config_close(parser); 721 config_close(parser);
722#endif
724} 723}
725 724
726#if ENABLE_FEATURE_USE_INITTAB 725#if ENABLE_FEATURE_USE_INITTAB
@@ -794,6 +793,10 @@ int init_main(int argc UNUSED_PARAM, char **argv)
794 } 793 }
795 /* Set up sig handlers -- be sure to 794 /* Set up sig handlers -- be sure to
796 * clear all of these in run() */ 795 * clear all of these in run() */
796// TODO: handlers should just set a flag variable.
797// Move signal handling from handlers to main loop -
798// we have bad races otherwise.
799// E.g. parse_inittab() vs. delete_init_action()...
797 signal(SIGQUIT, exec_restart_action); 800 signal(SIGQUIT, exec_restart_action);
798 bb_signals(0 801 bb_signals(0
799 + (1 << SIGUSR1) /* halt */ 802 + (1 << SIGUSR1) /* halt */
@@ -834,9 +837,9 @@ int init_main(int argc UNUSED_PARAM, char **argv)
834 if (ENABLE_SWAPONOFF) { 837 if (ENABLE_SWAPONOFF) {
835 struct sysinfo info; 838 struct sysinfo info;
836 839
837 if (!sysinfo(&info) && 840 if (sysinfo(&info) == 0
838 (info.mem_unit ? : 1) * (long long)info.totalram < 1024*1024) 841 && (info.mem_unit ? : 1) * (long long)info.totalram < 1024*1024
839 { 842 ) {
840 message(L_CONSOLE, "Low memory, forcing swapon"); 843 message(L_CONSOLE, "Low memory, forcing swapon");
841 /* swapon -a requires /proc typically */ 844 /* swapon -a requires /proc typically */
842 new_init_action(SYSINIT, "mount -t proc proc /proc", ""); 845 new_init_action(SYSINIT, "mount -t proc proc /proc", "");
@@ -877,7 +880,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
877 exit(EXIT_FAILURE); 880 exit(EXIT_FAILURE);
878 } 881 }
879 } 882 }
880#endif /* CONFIG_SELINUX */ 883#endif
881 884
882 /* Make the command line just say "init" - thats all, nothing else */ 885 /* Make the command line just say "init" - thats all, nothing else */
883 strncpy(argv[0], "init", strlen(argv[0])); 886 strncpy(argv[0], "init", strlen(argv[0]));