diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-09 21:35:07 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-09 21:35:07 +0000 |
commit | 3f3aa2a57dc648ade9083f3b3ad83cce8206b912 (patch) | |
tree | d5c648f583bb2edef25f05c2bed303df3d1a61f6 /libbb | |
parent | cd7001f7055c3fc2d6298ab9e3befe91e951c652 (diff) | |
download | busybox-w32-3f3aa2a57dc648ade9083f3b3ad83cce8206b912.tar.gz busybox-w32-3f3aa2a57dc648ade9083f3b3ad83cce8206b912.tar.bz2 busybox-w32-3f3aa2a57dc648ade9083f3b3ad83cce8206b912.zip |
make xfunctions optionally longjump instead of exit.
use it for making NOFORK more practical.
touch: make it a NOFORK applet
Diffstat (limited to 'libbb')
-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 |
5 files changed, 31 insertions, 12 deletions
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 | } |