3
0

xfunc_die.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. /* Keeping it separate allows to NOT suck in stdio for VERY small applets.
  10. * Try building busybox with only "true" enabled... */
  11. #include "libbb.h"
  12. int die_sleep;
  13. #if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_HUSH
  14. jmp_buf die_jmp;
  15. #endif
  16. void FAST_FUNC xfunc_die(void)
  17. {
  18. if (die_sleep) {
  19. if ((ENABLE_FEATURE_PREFER_APPLETS || ENABLE_HUSH)
  20. && die_sleep < 0
  21. ) {
  22. /* Special case. We arrive here if NOFORK applet
  23. * calls xfunc, which then decides to die.
  24. * We don't die, but jump instead back to caller.
  25. * NOFORK applets still cannot carelessly call xfuncs:
  26. * p = xmalloc(10);
  27. * q = xmalloc(10); // BUG! if this dies, we leak p!
  28. */
  29. /* -2222 means "zero" (longjmp can't pass 0)
  30. * run_nofork_applet() catches -2222. */
  31. longjmp(die_jmp, xfunc_error_retval ? xfunc_error_retval : -2222);
  32. }
  33. sleep(die_sleep);
  34. }
  35. exit(xfunc_error_retval);
  36. }