summaryrefslogtreecommitdiff
path: root/src/stdlib/quick_exit.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2024-01-31 01:11:36 -0500
committerJakob Kaivo <jkk@ung.org>2024-01-31 01:11:36 -0500
commit5ca5b53beccb061a4390d23493e670d9f8b65cd7 (patch)
tree8ab5d59341e41c7eceb02b2cb2272adc37fd5ef8 /src/stdlib/quick_exit.c
parentd2b6b441366cb56785a92694e19a084642c1c99e (diff)
fix up exit()/quick_exit() handlers
Diffstat (limited to 'src/stdlib/quick_exit.c')
-rw-r--r--src/stdlib/quick_exit.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/stdlib/quick_exit.c b/src/stdlib/quick_exit.c
index 06c69da8..3d754604 100644
--- a/src/stdlib/quick_exit.c
+++ b/src/stdlib/quick_exit.c
@@ -1,24 +1,35 @@
#include <stdlib.h>
#include "_stdlib.h"
+#include "_syscall.h"
/** cause normal quick program termination **/
_Noreturn void quick_exit(int status)
{
SIGNAL_SAFE(1);
+ if (__stdlib.quick_exit_called) {
+ __stdlib.constraint_handler("Undefined behavior: quick_exit() called twice", NULL, 0);
+ }
+ if (__stdlib.exit_called) {
+ __stdlib.constraint_handler("Undefined behavior: quick_exit() called after exit", NULL, 0);
+ }
+ __stdlib.quick_exit_called = 1;
+
/* execute all at_quick_exit() registered functions in reverse order */
- /*
- while (__stdlib.at_quick_exit) {
- __stdlib.at_quick_exit->fn();
- __stdlib.at_quick_exit = __stdlib.at_quick_exit->prev;
- }
- */
+ struct atexit *ae = &(__stdlib.at_quick_exit);
+ while (ae) {
+ int i = ae->nfns;
+ while (i > 0) {
+ ae->fns[--i]();
+ }
+ ae = ae->prev;
+ }
fflush(NULL);
// fclose(all the things);
// remove(all the tmpfile()s);
/* TODO */
- /* __syscall(exit, status); */
+
_Exit(status);
}