From eb24df9749994d175a2de3b7fc0535abe46a7576 Mon Sep 17 00:00:00 2001
From: Rob Landley
You can intercept this exit by assigning a setjmp/longjmp buffer to +
We replaced exit(), _exit(), and atexit() with xexit(), _xexit(), and +sigatexit(). This gives _xexit() the option to siglongjmp(toys.rebound, 1) +instead of exiting, lets xexit() report stdout flush failures to stderr +and change the exit code to indicate error, lets our toys.exit function +change happen for signal exit paths and lets us remove the functions +after we've called them.
+ +You can intercept our exit by assigning a setjmp/longjmp buffer to toys.rebound (set it back to zero to restore the default behavior). If you do this, cleaning up resource leaks is your problem.
void _xexit(void)
+Calls siglongjmp(toys.rebound, 1), or else _exit(toys.exitval). This +lets you ignore errors with the NO_EXIT() macro wrapper, or intercept +them with WOULD_EXIT().
+void xexit(void)
+Calls toys.xexit functions (if any) and flushes stdout/stderr (reporting +failure to write to stdout both to stderr and in the exit code), then +calls _xexit().
+