diff options
-rw-r--r-- | applets/applets.c | 2 | ||||
-rw-r--r-- | coreutils/cmp.c | 2 | ||||
-rw-r--r-- | coreutils/touch.c | 13 | ||||
-rw-r--r-- | include/applets.h | 2 | ||||
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | libbb/copyfd.c | 4 | ||||
-rw-r--r-- | libbb/error_msg_and_die.c | 11 | ||||
-rw-r--r-- | libbb/getopt32.c | 1 | ||||
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 25 | ||||
-rw-r--r-- | libbb/xfuncs.c | 2 |
10 files changed, 39 insertions, 24 deletions
diff --git a/applets/applets.c b/applets/applets.c index db4ee482e..9218b40e4 100644 --- a/applets/applets.c +++ b/applets/applets.c | |||
@@ -462,7 +462,7 @@ void bb_show_usage(void) | |||
462 | applet_name, usage_string); | 462 | applet_name, usage_string); |
463 | } | 463 | } |
464 | 464 | ||
465 | exit(xfunc_error_retval); | 465 | sleep_and_die(); |
466 | } | 466 | } |
467 | 467 | ||
468 | 468 | ||
diff --git a/coreutils/cmp.c b/coreutils/cmp.c index cff118279..c70f8822d 100644 --- a/coreutils/cmp.c +++ b/coreutils/cmp.c | |||
@@ -30,7 +30,7 @@ static FILE *cmp_xfopen_input(const char * const filename) | |||
30 | fp = fopen_or_warn_stdin(filename); | 30 | fp = fopen_or_warn_stdin(filename); |
31 | if (fp) | 31 | if (fp) |
32 | return fp; | 32 | return fp; |
33 | exit(xfunc_error_retval); /* We already output an error message. */ | 33 | sleep_and_die(); /* We already output an error message. */ |
34 | } | 34 | } |
35 | 35 | ||
36 | static const char fmt_eof[] = "cmp: EOF on %s\n"; | 36 | static const char fmt_eof[] = "cmp: EOF on %s\n"; |
diff --git a/coreutils/touch.c b/coreutils/touch.c index ae4e689f1..5f81b2380 100644 --- a/coreutils/touch.c +++ b/coreutils/touch.c | |||
@@ -17,21 +17,16 @@ | |||
17 | * Also, exiting on a failure was a bug. All args should be processed. | 17 | * Also, exiting on a failure was a bug. All args should be processed. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include <stdio.h> | ||
21 | #include <sys/types.h> | ||
22 | #include <fcntl.h> | ||
23 | #include <utime.h> | ||
24 | #include <errno.h> | ||
25 | #include <unistd.h> | ||
26 | #include <stdlib.h> | ||
27 | #include "busybox.h" | 20 | #include "busybox.h" |
28 | 21 | ||
22 | /* This is a NOFORK applet. Be very careful! */ | ||
23 | |||
29 | int touch_main(int argc, char **argv); | 24 | int touch_main(int argc, char **argv); |
30 | int touch_main(int argc, char **argv) | 25 | int touch_main(int argc, char **argv) |
31 | { | 26 | { |
32 | int fd; | 27 | int fd; |
33 | int status = EXIT_SUCCESS; | 28 | int status = EXIT_SUCCESS; |
34 | bool flags = (getopt32(argc, argv, "c") & 1); | 29 | int flags = getopt32(argc, argv, "c"); |
35 | 30 | ||
36 | argv += optind; | 31 | argv += optind; |
37 | 32 | ||
@@ -41,7 +36,7 @@ int touch_main(int argc, char **argv) | |||
41 | 36 | ||
42 | do { | 37 | do { |
43 | if (utime(*argv, NULL)) { | 38 | if (utime(*argv, NULL)) { |
44 | if (errno == ENOENT) { /* no such file*/ | 39 | if (errno == ENOENT) { /* no such file */ |
45 | if (flags) { /* Creation is disabled, so ignore. */ | 40 | if (flags) { /* Creation is disabled, so ignore. */ |
46 | continue; | 41 | continue; |
47 | } | 42 | } |
diff --git a/include/applets.h b/include/applets.h index 013903851..ecce32169 100644 --- a/include/applets.h +++ b/include/applets.h | |||
@@ -319,7 +319,7 @@ USE_TFTP(APPLET(tftp, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | |||
319 | #endif | 319 | #endif |
320 | USE_TIME(APPLET(time, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 320 | USE_TIME(APPLET(time, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
321 | USE_TOP(APPLET(top, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 321 | USE_TOP(APPLET(top, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
322 | USE_TOUCH(APPLET_NOEXEC(touch, touch, _BB_DIR_BIN, _BB_SUID_NEVER, touch)) | 322 | USE_TOUCH(APPLET_NOFORK(touch, touch, _BB_DIR_BIN, _BB_SUID_NEVER, touch)) |
323 | USE_TR(APPLET(tr, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 323 | USE_TR(APPLET(tr, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
324 | USE_TRACEROUTE(APPLET(traceroute, _BB_DIR_USR_BIN, _BB_SUID_MAYBE)) | 324 | USE_TRACEROUTE(APPLET(traceroute, _BB_DIR_USR_BIN, _BB_SUID_MAYBE)) |
325 | USE_TRUE(APPLET(true, _BB_DIR_BIN, _BB_SUID_NEVER)) | 325 | USE_TRUE(APPLET(true, _BB_DIR_BIN, _BB_SUID_NEVER)) |
diff --git a/include/libbb.h b/include/libbb.h index cec31a7f4..8e3f4023c 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -620,6 +620,7 @@ extern const char *msg_eol; | |||
620 | extern smallint logmode; | 620 | extern smallint logmode; |
621 | extern int die_sleep; | 621 | extern int die_sleep; |
622 | extern int xfunc_error_retval; | 622 | extern int xfunc_error_retval; |
623 | extern jmp_buf die_jmp; | ||
623 | extern void sleep_and_die(void) ATTRIBUTE_NORETURN; | 624 | extern void sleep_and_die(void) ATTRIBUTE_NORETURN; |
624 | extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE; | 625 | extern void bb_show_usage(void) ATTRIBUTE_NORETURN ATTRIBUTE_EXTERNALLY_VISIBLE; |
625 | extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); | 626 | extern void bb_error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
diff --git a/libbb/copyfd.c b/libbb/copyfd.c index 0d0ec2232..805b80187 100644 --- a/libbb/copyfd.c +++ b/libbb/copyfd.c | |||
@@ -77,7 +77,7 @@ void complain_copyfd_and_die(off_t sz) | |||
77 | if (sz != -1) | 77 | if (sz != -1) |
78 | bb_error_msg_and_die("short read"); | 78 | bb_error_msg_and_die("short read"); |
79 | /* if sz == -1, bb_copyfd_XX already complained */ | 79 | /* if sz == -1, bb_copyfd_XX already complained */ |
80 | exit(xfunc_error_retval); | 80 | sleep_and_die(); |
81 | } | 81 | } |
82 | #endif | 82 | #endif |
83 | 83 | ||
@@ -97,7 +97,7 @@ void bb_copyfd_exact_size(int fd1, int fd2, off_t size) | |||
97 | if (sz != -1) | 97 | if (sz != -1) |
98 | bb_error_msg_and_die("short read"); | 98 | bb_error_msg_and_die("short read"); |
99 | /* if sz == -1, bb_copyfd_XX already complained */ | 99 | /* if sz == -1, bb_copyfd_XX already complained */ |
100 | exit(xfunc_error_retval); | 100 | sleep_and_die(); |
101 | } | 101 | } |
102 | 102 | ||
103 | off_t bb_copyfd_eof(int fd1, int fd2) | 103 | off_t bb_copyfd_eof(int fd1, int fd2) |
diff --git a/libbb/error_msg_and_die.c b/libbb/error_msg_and_die.c index 7c5a4ebe9..39178a3ce 100644 --- a/libbb/error_msg_and_die.c +++ b/libbb/error_msg_and_die.c | |||
@@ -7,18 +7,19 @@ | |||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <stdio.h> | ||
11 | #include <errno.h> | ||
12 | #include <string.h> | ||
13 | #include <stdlib.h> | ||
14 | #include "libbb.h" | 10 | #include "libbb.h" |
15 | 11 | ||
16 | int die_sleep; | 12 | int die_sleep; |
13 | jmp_buf die_jmp; | ||
17 | 14 | ||
18 | void sleep_and_die(void) | 15 | void sleep_and_die(void) |
19 | { | 16 | { |
20 | if (die_sleep) | 17 | if (die_sleep) { |
18 | /* Special case: don't die, but jump */ | ||
19 | if (die_sleep < 0) | ||
20 | longjmp(die_jmp, xfunc_error_retval); | ||
21 | sleep(die_sleep); | 21 | sleep(die_sleep); |
22 | } | ||
22 | exit(xfunc_error_retval); | 23 | exit(xfunc_error_retval); |
23 | } | 24 | } |
24 | 25 | ||
diff --git a/libbb/getopt32.c b/libbb/getopt32.c index dec97d743..28b47974e 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c | |||
@@ -457,6 +457,7 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) | |||
457 | 457 | ||
458 | /* In case getopt32 was already called, reinit some state */ | 458 | /* In case getopt32 was already called, reinit some state */ |
459 | optind = 1; | 459 | optind = 1; |
460 | /* optarg = NULL; opterr = 0; optopt = 0; ?? */ | ||
460 | 461 | ||
461 | /* Note: just "getopt() <= 0" will not work good for | 462 | /* Note: just "getopt() <= 0" will not work good for |
462 | * "fake" short options, like this one: | 463 | * "fake" short options, like this one: |
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index d25693917..286ee2678 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c | |||
@@ -115,11 +115,27 @@ int spawn_and_wait(char **argv) | |||
115 | char **pp = argv; | 115 | char **pp = argv; |
116 | while (*++pp) | 116 | while (*++pp) |
117 | argc++; | 117 | argc++; |
118 | #ifdef BB_NOMMU | 118 | #ifndef BB_NOMMU |
119 | return a->main(argc, argv); | ||
120 | #else | ||
121 | if (a->nofork) | 119 | if (a->nofork) |
122 | return a->main(argc, argv); | 120 | #endif |
121 | { | ||
122 | int old_sleep = die_sleep; | ||
123 | die_sleep = -1; /* special flag */ | ||
124 | /* sleep_and_die() checks for it */ | ||
125 | rc = setjmp(die_jmp); | ||
126 | if (!rc) { | ||
127 | const struct BB_applet *old_a = current_applet; | ||
128 | current_applet = a; | ||
129 | applet_name = a->name; | ||
130 | // what else should we save/restore? | ||
131 | rc = a->main(argc, argv); | ||
132 | current_applet = old_a; | ||
133 | applet_name = old_a->name; | ||
134 | } | ||
135 | die_sleep = old_sleep; | ||
136 | return rc; | ||
137 | } | ||
138 | #ifndef BB_NOMMU /* MMU only */ | ||
123 | /* a->noexec is true */ | 139 | /* a->noexec is true */ |
124 | rc = fork(); | 140 | rc = fork(); |
125 | if (rc) | 141 | if (rc) |
@@ -135,6 +151,7 @@ int spawn_and_wait(char **argv) | |||
135 | return wait4pid(rc); | 151 | return wait4pid(rc); |
136 | } | 152 | } |
137 | 153 | ||
154 | |||
138 | #if 0 //ndef BB_NOMMU | 155 | #if 0 //ndef BB_NOMMU |
139 | // Die with an error message if we can't daemonize. | 156 | // Die with an error message if we can't daemonize. |
140 | void xdaemon(int nochdir, int noclose) | 157 | void xdaemon(int nochdir, int noclose) |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 0cf2005ac..fa4a15236 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -476,7 +476,7 @@ void xprint_and_close_file(FILE *file) | |||
476 | fflush(stdout); | 476 | fflush(stdout); |
477 | // copyfd outputs error messages for us. | 477 | // copyfd outputs error messages for us. |
478 | if (bb_copyfd_eof(fileno(file), 1) == -1) | 478 | if (bb_copyfd_eof(fileno(file), 1) == -1) |
479 | exit(xfunc_error_retval); | 479 | sleep_and_die(); |
480 | 480 | ||
481 | fclose(file); | 481 | fclose(file); |
482 | } | 482 | } |