lineedit: nuke two unused variables and code which sets them
[oweals/busybox.git] / libbb / error_msg_and_die.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * Utility routines.
4  *
5  * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6  *
7  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8  */
9
10 #include "libbb.h"
11
12 int die_sleep;
13 #if ENABLE_FEATURE_PREFER_APPLETS
14 jmp_buf die_jmp;
15 #endif
16
17 void xfunc_die(void)
18 {
19         if (die_sleep) {
20                 if (ENABLE_FEATURE_PREFER_APPLETS && die_sleep < 0) {
21                         /* Special case. We arrive here if NOFORK applet
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                 }
32                 sleep(die_sleep);
33         }
34         exit(xfunc_error_retval);
35 }
36
37 void bb_error_msg_and_die(const char *s, ...)
38 {
39         va_list p;
40
41         va_start(p, s);
42         bb_verror_msg(s, p, NULL);
43         va_end(p);
44         xfunc_die();
45 }