diff options
author | Jakob Kaivo <jkk@ung.org> | 2024-01-31 01:11:36 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2024-01-31 01:11:36 -0500 |
commit | 5ca5b53beccb061a4390d23493e670d9f8b65cd7 (patch) | |
tree | 8ab5d59341e41c7eceb02b2cb2272adc37fd5ef8 /src/stdlib/quick_exit.c | |
parent | d2b6b441366cb56785a92694e19a084642c1c99e (diff) |
fix up exit()/quick_exit() handlers
Diffstat (limited to 'src/stdlib/quick_exit.c')
-rw-r--r-- | src/stdlib/quick_exit.c | 25 |
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); } |