aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--include/libbb.h1
-rw-r--r--init/init.c52
-rw-r--r--libbb/error_msg_and_die.c11
-rw-r--r--libbb/fflush_stdout_and_exit.c7
-rw-r--r--libbb/herror_msg_and_die.c4
-rw-r--r--libbb/perror_msg_and_die.c4
-rw-r--r--miscutils/crond.c4
-rw-r--r--networking/httpd.c4
-rw-r--r--util-linux/fdisk_sgi.c2
9 files changed, 44 insertions, 45 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 13303073d..7ee66dce6 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -397,6 +397,7 @@ extern const char *msg_eol;
397extern int logmode; 397extern int logmode;
398extern int die_sleep; 398extern int die_sleep;
399extern int xfunc_error_retval; 399extern int xfunc_error_retval;
400extern void sleep_and_die(void) ATTRIBUTE_NORETURN;
400extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE; 401extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE;
401extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); 402extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
402extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); 403extern void bb_error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
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 */
diff --git a/libbb/error_msg_and_die.c b/libbb/error_msg_and_die.c
index 10d953513..7c5a4ebe9 100644
--- a/libbb/error_msg_and_die.c
+++ b/libbb/error_msg_and_die.c
@@ -15,6 +15,13 @@
15 15
16int die_sleep; 16int die_sleep;
17 17
18void sleep_and_die(void)
19{
20 if (die_sleep)
21 sleep(die_sleep);
22 exit(xfunc_error_retval);
23}
24
18void bb_error_msg_and_die(const char *s, ...) 25void bb_error_msg_and_die(const char *s, ...)
19{ 26{
20 va_list p; 27 va_list p;
@@ -22,7 +29,5 @@ void bb_error_msg_and_die(const char *s, ...)
22 va_start(p, s); 29 va_start(p, s);
23 bb_verror_msg(s, p, NULL); 30 bb_verror_msg(s, p, NULL);
24 va_end(p); 31 va_end(p);
25 if (die_sleep) 32 sleep_and_die();
26 sleep(die_sleep);
27 exit(xfunc_error_retval);
28} 33}
diff --git a/libbb/fflush_stdout_and_exit.c b/libbb/fflush_stdout_and_exit.c
index 456ce9513..6f44770c6 100644
--- a/libbb/fflush_stdout_and_exit.c
+++ b/libbb/fflush_stdout_and_exit.c
@@ -15,10 +15,7 @@
15 15
16void fflush_stdout_and_exit(int retval) 16void fflush_stdout_and_exit(int retval)
17{ 17{
18 if (fflush(stdout)) { 18 if (fflush(stdout))
19 retval = xfunc_error_retval; 19 sleep_and_die();
20 }
21 if (die_sleep)
22 sleep(die_sleep);
23 exit(retval); 20 exit(retval);
24} 21}
diff --git a/libbb/herror_msg_and_die.c b/libbb/herror_msg_and_die.c
index f62ddd2ea..a7a22caf7 100644
--- a/libbb/herror_msg_and_die.c
+++ b/libbb/herror_msg_and_die.c
@@ -19,7 +19,5 @@ void bb_herror_msg_and_die(const char *s, ...)
19 va_start(p, s); 19 va_start(p, s);
20 bb_vherror_msg(s, p); 20 bb_vherror_msg(s, p);
21 va_end(p); 21 va_end(p);
22 if (die_sleep) 22 sleep_and_die();
23 sleep(die_sleep);
24 exit(xfunc_error_retval);
25} 23}
diff --git a/libbb/perror_msg_and_die.c b/libbb/perror_msg_and_die.c
index 2303ba211..7521e7157 100644
--- a/libbb/perror_msg_and_die.c
+++ b/libbb/perror_msg_and_die.c
@@ -20,7 +20,5 @@ void bb_perror_msg_and_die(const char *s, ...)
20 va_start(p, s); 20 va_start(p, s);
21 bb_vperror_msg(s, p); 21 bb_vperror_msg(s, p);
22 va_end(p); 22 va_end(p);
23 if (die_sleep) 23 sleep_and_die();
24 sleep(die_sleep);
25 exit(xfunc_error_retval);
26} 24}
diff --git a/miscutils/crond.c b/miscutils/crond.c
index fa7964e4e..aace3ee18 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -542,7 +542,7 @@ static void SynchronizeFile(const char *fileName)
542 struct stat sbuf; 542 struct stat sbuf;
543 543
544 if (fstat(fileno(fi), &sbuf) == 0 && sbuf.st_uid == DaemonUid) { 544 if (fstat(fileno(fi), &sbuf) == 0 && sbuf.st_uid == DaemonUid) {
545 CronFile *file = calloc(1, sizeof(CronFile)); 545 CronFile *file = xzalloc(sizeof(CronFile));
546 CronLine **pline; 546 CronLine **pline;
547 547
548 file->cf_User = strdup(fileName); 548 file->cf_User = strdup(fileName);
@@ -586,7 +586,7 @@ static void SynchronizeFile(const char *fileName)
586 586
587 FixDayDow(&line); 587 FixDayDow(&line);
588 588
589 *pline = calloc(1, sizeof(CronLine)); 589 *pline = xzalloc(sizeof(CronLine));
590 **pline = line; 590 **pline = line;
591 591
592 /* copy command */ 592 /* copy command */
diff --git a/networking/httpd.c b/networking/httpd.c
index e50955ddc..ff5c14672 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -499,7 +499,7 @@ static void parse_conf(const char *path, int flag)
499 continue; 499 continue;
500 if (*p0 == 'A' || *p0 == 'D') { 500 if (*p0 == 'A' || *p0 == 'D') {
501 /* storing current config IP line */ 501 /* storing current config IP line */
502 pip = calloc(1, sizeof(Htaccess_IP)); 502 pip = xzalloc(sizeof(Htaccess_IP));
503 if (pip) { 503 if (pip) {
504 if (scan_ip_mask(c, &(pip->ip), &(pip->mask))) { 504 if (scan_ip_mask(c, &(pip->ip), &(pip->mask))) {
505 /* syntax IP{/mask} error detected, protect all */ 505 /* syntax IP{/mask} error detected, protect all */
@@ -570,7 +570,7 @@ static void parse_conf(const char *path, int flag)
570 || ENABLE_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES \ 570 || ENABLE_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES \
571 || ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR 571 || ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
572 /* storing current config line */ 572 /* storing current config line */
573 cur = calloc(1, sizeof(Htaccess) + strlen(p0)); 573 cur = xzalloc(sizeof(Htaccess) + strlen(p0));
574 if (cur) { 574 if (cur) {
575 cf = strcpy(cur->before_colon, p0); 575 cf = strcpy(cur->before_colon, p0);
576 c = strchr(cf, ':'); 576 c = strchr(cf, ':');
diff --git a/util-linux/fdisk_sgi.c b/util-linux/fdisk_sgi.c
index d8acd6bc7..c83ef2420 100644
--- a/util-linux/fdisk_sgi.c
+++ b/util-linux/fdisk_sgi.c
@@ -869,7 +869,7 @@ sgi_set_xcyl(void)
869static sgiinfo * 869static sgiinfo *
870fill_sgiinfo(void) 870fill_sgiinfo(void)
871{ 871{
872 sgiinfo *info = calloc(1, sizeof(sgiinfo)); 872 sgiinfo *info = xzalloc(sizeof(sgiinfo));
873 873
874 info->magic = SGI_SSWAP32(SGI_INFO_MAGIC); 874 info->magic = SGI_SSWAP32(SGI_INFO_MAGIC);
875 info->b1 = SGI_SSWAP32(-1); 875 info->b1 = SGI_SSWAP32(-1);