aboutsummaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-01-03 02:56:00 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2007-01-03 02:56:00 +0000
commitcd4370bd6ed20fd2c944f03206d3cd56023f390f (patch)
tree66b3617e0b6ceed9c3123000104df0d78bf9bf2a /init
parentb0c043bbed7ee35df4171d8551695c74458c8d97 (diff)
downloadbusybox-w32-cd4370bd6ed20fd2c944f03206d3cd56023f390f.tar.gz
busybox-w32-cd4370bd6ed20fd2c944f03206d3cd56023f390f.tar.bz2
busybox-w32-cd4370bd6ed20fd2c944f03206d3cd56023f390f.zip
convert calloc to xzalloc
fix sleep-on-die option git-svn-id: svn://busybox.net/trunk/busybox@17140 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'init')
-rw-r--r--init/init.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/init/init.c b/init/init.c
index 2e8ca3ca8..6fc68afb1 100644
--- a/init/init.c
+++ b/init/init.c
@@ -19,7 +19,7 @@
19 19
20#include "init_shared.h" 20#include "init_shared.h"
21 21
22#ifdef CONFIG_SYSLOGD 22#if ENABLE_SYSLOGD
23# include <sys/syslog.h> 23# include <sys/syslog.h>
24#endif 24#endif
25 25
@@ -60,7 +60,7 @@ struct serial_struct {
60#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin" 60#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
61#endif 61#endif
62 62
63#if defined CONFIG_FEATURE_INIT_COREDUMPS 63#if ENABLE_FEATURE_INIT_COREDUMPS
64/* 64/*
65 * When a file named CORE_ENABLE_FLAG_FILE exists, setrlimit is called 65 * When a file named CORE_ENABLE_FLAG_FILE exists, setrlimit is called
66 * before processes are spawned to set core file size as unlimited. 66 * before processes are spawned to set core file size as unlimited.
@@ -121,7 +121,7 @@ struct init_action {
121static struct init_action *init_action_list = NULL; 121static struct init_action *init_action_list = NULL;
122static char console[CONSOLE_BUFF_SIZE] = CONSOLE_DEV; 122static char console[CONSOLE_BUFF_SIZE] = CONSOLE_DEV;
123 123
124#ifndef CONFIG_SYSLOGD 124#if !ENABLE_SYSLOGD
125static char *log_console = VC_5; 125static char *log_console = VC_5;
126#endif 126#endif
127#if !ENABLE_DEBUG_INIT 127#if !ENABLE_DEBUG_INIT
@@ -132,7 +132,7 @@ enum {
132 LOG = 0x1, 132 LOG = 0x1,
133 CONSOLE = 0x2, 133 CONSOLE = 0x2,
134 134
135#if defined CONFIG_FEATURE_EXTRA_QUIET 135#if ENABLE_FEATURE_EXTRA_QUIET
136 MAYBE_CONSOLE = 0x0, 136 MAYBE_CONSOLE = 0x0,
137#else 137#else
138 MAYBE_CONSOLE = CONSOLE, 138 MAYBE_CONSOLE = CONSOLE,
@@ -162,11 +162,13 @@ static int waitfor(const struct init_action *a, pid_t pid);
162static void shutdown_signal(int sig); 162static void shutdown_signal(int sig);
163#endif 163#endif
164 164
165#if !ENABLE_DEBUG_INIT
165static void loop_forever(void) 166static void loop_forever(void)
166{ 167{
167 while (1) 168 while (1)
168 sleep(1); 169 sleep(1);
169} 170}
171#endif
170 172
171/* Print a message to the specified device. 173/* Print a message to the specified device.
172 * Device may be bitwise-or'd from LOG | CONSOLE */ 174 * Device may be bitwise-or'd from LOG | CONSOLE */
@@ -182,7 +184,7 @@ static void message(int device, const char *fmt, ...)
182 va_list arguments; 184 va_list arguments;
183 int l; 185 int l;
184 RESERVE_CONFIG_BUFFER(msg, 1024); 186 RESERVE_CONFIG_BUFFER(msg, 1024);
185#ifndef CONFIG_SYSLOGD 187#if !ENABLE_SYSLOGD
186 static int log_fd = -1; 188 static int log_fd = -1;
187#endif 189#endif
188 190
@@ -191,7 +193,7 @@ static void message(int device, const char *fmt, ...)
191 l = vsnprintf(msg + 1, 1024 - 2, fmt, arguments) + 1; 193 l = vsnprintf(msg + 1, 1024 - 2, fmt, arguments) + 1;
192 va_end(arguments); 194 va_end(arguments);
193 195
194#ifdef CONFIG_SYSLOGD 196#if ENABLE_SYSLOGD
195 /* Log the message to syslogd */ 197 /* Log the message to syslogd */
196 if (device & LOG) { 198 if (device & LOG) {
197 /* don`t out "\r\n" */ 199 /* don`t out "\r\n" */
@@ -313,7 +315,7 @@ static void console_init(void)
313 } 315 }
314 if (fd < 0) { 316 if (fd < 0) {
315 /* Perhaps we should panic here? */ 317 /* Perhaps we should panic here? */
316#ifndef CONFIG_SYSLOGD 318#if !ENABLE_SYSLOGD
317 log_console = 319 log_console =
318#endif 320#endif
319 safe_strncpy(console, bb_dev_null, sizeof(console)); 321 safe_strncpy(console, bb_dev_null, sizeof(console));
@@ -325,7 +327,7 @@ static void console_init(void)
325 * if TERM is set to linux (the default) */ 327 * if TERM is set to linux (the default) */
326 if (s == NULL || strcmp(s, "linux") == 0) 328 if (s == NULL || strcmp(s, "linux") == 0)
327 putenv("TERM=vt102"); 329 putenv("TERM=vt102");
328#ifndef CONFIG_SYSLOGD 330#if !ENABLE_SYSLOGD
329 log_console = console; 331 log_console = console;
330#endif 332#endif
331 } else { 333 } else {
@@ -510,7 +512,7 @@ static pid_t run(const struct init_action *a)
510 cmd[0][0] = '-'; 512 cmd[0][0] = '-';
511 strcpy(cmd[0] + 1, s); 513 strcpy(cmd[0] + 1, s);
512 } 514 }
513#ifdef CONFIG_FEATURE_INIT_SCTTY 515#if ENABLE_FEATURE_INIT_SCTTY
514 /* Establish this process as session leader and 516 /* Establish this process as session leader and
515 * (attempt) to make the tty (if any) a controlling tty. 517 * (attempt) to make the tty (if any) a controlling tty.
516 */ 518 */
@@ -543,7 +545,7 @@ static pid_t run(const struct init_action *a)
543 message(LOG, "Starting pid %d, console %s: '%s'", 545 message(LOG, "Starting pid %d, console %s: '%s'",
544 getpid(), a->terminal, cmdpath); 546 getpid(), a->terminal, cmdpath);
545 547
546#if defined CONFIG_FEATURE_INIT_COREDUMPS 548#if ENABLE_FEATURE_INIT_COREDUMPS
547 { 549 {
548 struct stat sb; 550 struct stat sb;
549 if (stat(CORE_ENABLE_FLAG_FILE, &sb) == 0) { 551 if (stat(CORE_ENABLE_FLAG_FILE, &sb) == 0) {
@@ -622,11 +624,12 @@ static void init_reboot(unsigned long magic)
622 /* We have to fork here, since the kernel calls do_exit(0) in 624 /* We have to fork here, since the kernel calls do_exit(0) in
623 * linux/kernel/sys.c, which can cause the machine to panic when 625 * linux/kernel/sys.c, which can cause the machine to panic when
624 * the init process is killed.... */ 626 * the init process is killed.... */
625 if ((pid = fork()) == 0) { 627 pid = vfork();
628 if (pid == 0) { /* child */
626 reboot(magic); 629 reboot(magic);
627 _exit(0); 630 _exit(0);
628 } 631 }
629 waitpid (pid, NULL, 0); 632 waitpid(pid, NULL, 0);
630} 633}
631 634
632static void shutdown_system(void) 635static void shutdown_system(void)
@@ -746,7 +749,6 @@ static void shutdown_signal(int sig)
746 sleep(2); 749 sleep(2);
747 750
748 init_reboot(rb); 751 init_reboot(rb);
749
750 loop_forever(); 752 loop_forever();
751} 753}
752 754
@@ -785,11 +787,7 @@ static void new_init_action(int action, const char *command, const char *cons)
785 if (strcmp(cons, bb_dev_null) == 0 && (action & ASKFIRST)) 787 if (strcmp(cons, bb_dev_null) == 0 && (action & ASKFIRST))
786 return; 788 return;
787 789
788 new_action = calloc((size_t) (1), sizeof(struct init_action)); 790 new_action = xzalloc(sizeof(struct init_action));
789 if (!new_action) {
790 message(LOG | CONSOLE, "Memory allocation failure");
791 loop_forever();
792 }
793 791
794 /* Append to the end of the list */ 792 /* Append to the end of the list */
795 for (a = last = init_action_list; a; a = a->next) { 793 for (a = last = init_action_list; a; a = a->next) {
@@ -841,7 +839,7 @@ static void delete_init_action(struct init_action *action)
841 */ 839 */
842static void parse_inittab(void) 840static void parse_inittab(void)
843{ 841{
844#ifdef CONFIG_FEATURE_USE_INITTAB 842#if ENABLE_FEATURE_USE_INITTAB
845 FILE *file; 843 FILE *file;
846 char buf[INIT_BUFFS_SIZE], lineAsRead[INIT_BUFFS_SIZE]; 844 char buf[INIT_BUFFS_SIZE], lineAsRead[INIT_BUFFS_SIZE];
847 char tmpConsole[CONSOLE_BUFF_SIZE]; 845 char tmpConsole[CONSOLE_BUFF_SIZE];
@@ -870,7 +868,7 @@ static void parse_inittab(void)
870 new_init_action(SYSINIT, INIT_SCRIPT, ""); 868 new_init_action(SYSINIT, INIT_SCRIPT, "");
871 869
872 return; 870 return;
873#ifdef CONFIG_FEATURE_USE_INITTAB 871#if ENABLE_FEATURE_USE_INITTAB
874 } 872 }
875 873
876 while (fgets(buf, INIT_BUFFS_SIZE, file) != NULL) { 874 while (fgets(buf, INIT_BUFFS_SIZE, file) != NULL) {
@@ -941,10 +939,10 @@ static void parse_inittab(void)
941 } 939 }
942 fclose(file); 940 fclose(file);
943 return; 941 return;
944#endif /* CONFIG_FEATURE_USE_INITTAB */ 942#endif /* FEATURE_USE_INITTAB */
945} 943}
946 944
947#ifdef CONFIG_FEATURE_USE_INITTAB 945#if ENABLE_FEATURE_USE_INITTAB
948static void reload_signal(int sig ATTRIBUTE_UNUSED) 946static void reload_signal(int sig ATTRIBUTE_UNUSED)
949{ 947{
950 struct init_action *a, *tmp; 948 struct init_action *a, *tmp;
@@ -969,13 +967,15 @@ static void reload_signal(int sig ATTRIBUTE_UNUSED)
969 run_actions(RESPAWN); 967 run_actions(RESPAWN);
970 return; 968 return;
971} 969}
972#endif /* CONFIG_FEATURE_USE_INITTAB */ 970#endif /* FEATURE_USE_INITTAB */
973 971
974int init_main(int argc, char **argv) 972int init_main(int argc, char **argv)
975{ 973{
976 struct init_action *a; 974 struct init_action *a;
977 pid_t wpid; 975 pid_t wpid;
978 976
977 die_sleep = 30 * 24*60*60; /* if xmalloc will ever die... */
978
979 if (argc > 1 && !strcmp(argv[1], "-q")) { 979 if (argc > 1 && !strcmp(argv[1], "-q")) {
980 return kill(1,SIGHUP); 980 return kill(1,SIGHUP);
981 } 981 }
@@ -1062,7 +1062,7 @@ int init_main(int argc, char **argv)
1062 parse_inittab(); 1062 parse_inittab();
1063 } 1063 }
1064 1064
1065#ifdef CONFIG_SELINUX 1065#if ENABLE_SELINUX
1066 if (getenv("SELINUX_INIT") == NULL) { 1066 if (getenv("SELINUX_INIT") == NULL) {
1067 int enforce = 0; 1067 int enforce = 0;
1068 1068
@@ -1092,12 +1092,12 @@ int init_main(int argc, char **argv)
1092 /* Next run anything to be run only once */ 1092 /* Next run anything to be run only once */
1093 run_actions(ONCE); 1093 run_actions(ONCE);
1094 1094
1095#ifdef CONFIG_FEATURE_USE_INITTAB 1095#if ENABLE_FEATURE_USE_INITTAB
1096 /* Redefine SIGHUP to reread /etc/inittab */ 1096 /* Redefine SIGHUP to reread /etc/inittab */
1097 signal(SIGHUP, reload_signal); 1097 signal(SIGHUP, reload_signal);
1098#else 1098#else
1099 signal(SIGHUP, SIG_IGN); 1099 signal(SIGHUP, SIG_IGN);
1100#endif /* CONFIG_FEATURE_USE_INITTAB */ 1100#endif /* FEATURE_USE_INITTAB */
1101 1101
1102 1102
1103 /* Now run the looping stuff for the rest of forever */ 1103 /* Now run the looping stuff for the rest of forever */