diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2015-01-03 13:58:15 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2015-01-03 13:58:15 +0100 |
commit | 4aca87515a5083ae0e31ce3177189fd43b6d05ac (patch) | |
tree | 7b1d9a31393ca090757dc6f0d3859b4fcd93f271 /release/src/router/busybox/libbb/xfunc_die.c | |
parent | 008d0be72b2f160382c6e880765e96b64a050c65 (diff) | |
download | tomato-4aca87515a5083ae0e31ce3177189fd43b6d05ac.tar.gz tomato-4aca87515a5083ae0e31ce3177189fd43b6d05ac.tar.bz2 |
patch to Vanilla Tomato 1.28
Diffstat (limited to 'release/src/router/busybox/libbb/xfunc_die.c')
-rw-r--r-- | release/src/router/busybox/libbb/xfunc_die.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/release/src/router/busybox/libbb/xfunc_die.c b/release/src/router/busybox/libbb/xfunc_die.c new file mode 100644 index 00000000..ba9fe935 --- /dev/null +++ b/release/src/router/busybox/libbb/xfunc_die.c @@ -0,0 +1,40 @@ +/* vi: set sw=4 ts=4: */ +/* + * Utility routines. + * + * Copyright (C) 2008 by Denys Vlasenko <vda.linux@googlemail.com> + * + * Licensed under GPLv2, see file LICENSE in this tarball for details. + */ + +/* Keeping it separate allows to NOT suck in stdio for VERY small applets. + * Try building busybox with only "true" enabled... */ + +#include "libbb.h" + +int die_sleep; +#if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_HUSH +jmp_buf die_jmp; +#endif + +void FAST_FUNC xfunc_die(void) +{ + if (die_sleep) { + if ((ENABLE_FEATURE_PREFER_APPLETS || ENABLE_HUSH) + && die_sleep < 0 + ) { + /* Special case. We arrive here if NOFORK applet + * calls xfunc, which then decides to die. + * We don't die, but jump instead back to caller. + * NOFORK applets still cannot carelessly call xfuncs: + * p = xmalloc(10); + * q = xmalloc(10); // BUG! if this dies, we leak p! + */ + /* -2222 means "zero" (longjmp can't pass 0) + * run_nofork_applet() catches -2222. */ + longjmp(die_jmp, xfunc_error_retval ? xfunc_error_retval : -2222); + } + sleep(die_sleep); + } + exit(xfunc_error_retval); +} |