error_msg_and_die.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #include "libbb.h"
  10. int die_sleep;
  11. #if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_HUSH
  12. jmp_buf die_jmp;
  13. #endif
  14. void xfunc_die(void)
  15. {
  16. if (die_sleep) {
  17. if ((ENABLE_FEATURE_PREFER_APPLETS || ENABLE_HUSH)
  18. && die_sleep < 0
  19. ) {
  20. /* Special case. We arrive here if NOFORK applet
  21. * calls xfunc, which then decides to die.
  22. * We don't die, but jump instead back to caller.
  23. * NOFORK applets still cannot carelessly call xfuncs:
  24. * p = xmalloc(10);
  25. * q = xmalloc(10); // BUG! if this dies, we leak p!
  26. */
  27. /* -2222 means "zero" (longjmp can't pass 0)
  28. * run_nofork_applet() catches -2222. */
  29. longjmp(die_jmp, xfunc_error_retval ? xfunc_error_retval : -2222);
  30. }
  31. sleep(die_sleep);
  32. }
  33. exit(xfunc_error_retval);
  34. }
  35. void bb_error_msg_and_die(const char *s, ...)
  36. {
  37. va_list p;
  38. va_start(p, s);
  39. bb_verror_msg(s, p, NULL);
  40. va_end(p);
  41. xfunc_die();
  42. }