diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-01 17:43:03 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-04-01 17:43:03 +0000 |
commit | 0edbdd8ac8c0add7902d73a7ef921abba9f5752a (patch) | |
tree | 364657f4a4613a7cdaab1e7b43e058f75a73b45e | |
parent | c59d802a5aa70c0c8f1f9fb8478351c6cbc3f86d (diff) | |
download | busybox-w32-0edbdd8ac8c0add7902d73a7ef921abba9f5752a.tar.gz busybox-w32-0edbdd8ac8c0add7902d73a7ef921abba9f5752a.tar.bz2 busybox-w32-0edbdd8ac8c0add7902d73a7ef921abba9f5752a.zip |
xfunc_die: resurrect (actually, it's "svn add" being forgotten again)
-rw-r--r-- | libbb/xfunc_die.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/libbb/xfunc_die.c b/libbb/xfunc_die.c new file mode 100644 index 000000000..357494d34 --- /dev/null +++ b/libbb/xfunc_die.c | |||
@@ -0,0 +1,40 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Utility routines. | ||
4 | * | ||
5 | * Copyright (C) 2008 by Denys Vlasenko <vda.linux@googlemail.com> | ||
6 | * | ||
7 | * Licensed under GPLv2, see file LICENSE in this tarball for details. | ||
8 | */ | ||
9 | |||
10 | /* Keeping it separate allows to NOT suck in stdio for VERY small applets. | ||
11 | * Try building busybox with only "true" enabled... */ | ||
12 | |||
13 | #include "libbb.h" | ||
14 | |||
15 | int die_sleep; | ||
16 | #if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_HUSH | ||
17 | jmp_buf die_jmp; | ||
18 | #endif | ||
19 | |||
20 | void xfunc_die(void) | ||
21 | { | ||
22 | if (die_sleep) { | ||
23 | if ((ENABLE_FEATURE_PREFER_APPLETS || ENABLE_HUSH) | ||
24 | && die_sleep < 0 | ||
25 | ) { | ||
26 | /* Special case. We arrive here if NOFORK applet | ||
27 | * calls xfunc, which then decides to die. | ||
28 | * We don't die, but jump instead back to caller. | ||
29 | * NOFORK applets still cannot carelessly call xfuncs: | ||
30 | * p = xmalloc(10); | ||
31 | * q = xmalloc(10); // BUG! if this dies, we leak p! | ||
32 | */ | ||
33 | /* -2222 means "zero" (longjmp can't pass 0) | ||
34 | * run_nofork_applet() catches -2222. */ | ||
35 | longjmp(die_jmp, xfunc_error_retval ? xfunc_error_retval : -2222); | ||
36 | } | ||
37 | sleep(die_sleep); | ||
38 | } | ||
39 | exit(xfunc_error_retval); | ||
40 | } | ||