summaryrefslogtreecommitdiff
path: root/libbb/error_msg_and_die.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-10 21:38:30 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-10 21:38:30 +0000
commit335b63d8d1876ce4e172ebcc9d64544785682244 (patch)
tree14183fd728ce51ae10baee70f7d8f72c39d30649 /libbb/error_msg_and_die.c
parent07c394e69b0cfa7cd30e97ffc6edb0d857905f45 (diff)
downloadbusybox-w32-335b63d8d1876ce4e172ebcc9d64544785682244.tar.gz
busybox-w32-335b63d8d1876ce4e172ebcc9d64544785682244.tar.bz2
busybox-w32-335b63d8d1876ce4e172ebcc9d64544785682244.zip
make a few struct bb_applet members conditional
rename sllep_and_die -> xfunc_die make fflush_stdout_and_exit NOFORK-safe fix some buglets found by randomconfig
Diffstat (limited to 'libbb/error_msg_and_die.c')
-rw-r--r--libbb/error_msg_and_die.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/libbb/error_msg_and_die.c b/libbb/error_msg_and_die.c
index 39178a3ce..4a9049364 100644
--- a/libbb/error_msg_and_die.c
+++ b/libbb/error_msg_and_die.c
@@ -10,14 +10,25 @@
10#include "libbb.h" 10#include "libbb.h"
11 11
12int die_sleep; 12int die_sleep;
13#if ENABLE_FEATURE_EXEC_PREFER_APPLETS
13jmp_buf die_jmp; 14jmp_buf die_jmp;
15#endif
14 16
15void sleep_and_die(void) 17void xfunc_die(void)
16{ 18{
17 if (die_sleep) { 19 if (die_sleep) {
18 /* Special case: don't die, but jump */ 20 if (ENABLE_FEATURE_EXEC_PREFER_APPLETS && die_sleep < 0) {
19 if (die_sleep < 0) 21 /* Special case. We arrive here if NOFORK applet
20 longjmp(die_jmp, xfunc_error_retval); 22 * calls xfunc, which then decides to die.
23 * We don't die, but jump instead back to caller.
24 * NOFORK applets still cannot carelessly call xfuncs:
25 * p = xmalloc(10);
26 * q = xmalloc(10); // BUG! if this dies, we leak p!
27 */
28 /* -111 means "zero" (longjmp can't pass 0)
29 * spawn_and_wait() catches -111. */
30 longjmp(die_jmp, xfunc_error_retval ? xfunc_error_retval : -111);
31 }
21 sleep(die_sleep); 32 sleep(die_sleep);
22 } 33 }
23 exit(xfunc_error_retval); 34 exit(xfunc_error_retval);
@@ -30,5 +41,5 @@ void bb_error_msg_and_die(const char *s, ...)
30 va_start(p, s); 41 va_start(p, s);
31 bb_verror_msg(s, p, NULL); 42 bb_verror_msg(s, p, NULL);
32 va_end(p); 43 va_end(p);
33 sleep_and_die(); 44 xfunc_die();
34} 45}