block all signals (even internal ones) in cancellation signal handler
[musl] / src / exit / atexit.c
index 1b40cb9..be82718 100644 (file)
@@ -1,7 +1,5 @@
-#include <stddef.h>
 #include <stdlib.h>
 #include <stdint.h>
-#include <limits.h>
 #include "libc.h"
 
 /* Ensure that at least 32 atexit handlers can be registered without malloc */
@@ -14,16 +12,15 @@ static struct fl
        void *a[COUNT];
 } builtin, *head;
 
-static int lock[2];
+static volatile int lock[2];
 
 void __funcs_on_exit()
 {
        int i;
        void (*func)(void *), *arg;
        LOCK(lock);
-       for (; head; head=head->next) {
-               for (i=COUNT-1; i>=0 && !head->f[i]; i--);
-               if (i<0) continue;
+       for (; head; head=head->next) for (i=COUNT-1; i>=0; i--) {
+               if (!head->f[i]) continue;
                func = head->f[i];
                arg = head->a[i];
                head->f[i] = 0;