basic/sigbus: use FOREACH_ELEMENT where appropriate, assert >= 0 for success
authorMike Yuan <me@yhndnzj.com>
Sat, 17 Aug 2024 17:40:55 +0000 (19:40 +0200)
committerMike Yuan <me@yhndnzj.com>
Thu, 22 Aug 2024 18:14:25 +0000 (20:14 +0200)
src/basic/sigbus.c

index 47ab0b81d887622cb769b229fa19da014e9a6205..e8d2fdb79a05ce5b9fd693ed6e9ae1549acf13cc 100644 (file)
@@ -29,10 +29,10 @@ static void sigbus_push(void *addr) {
         assert(addr);
 
         /* Find a free place, increase the number of entries and leave, if we can */
-        for (size_t u = 0; u < SIGBUS_QUEUE_MAX; u++) {
+        FOREACH_ELEMENT(u, sigbus_queue) {
                 /* OK to initialize this here since we haven't started the atomic ops yet */
                 void *tmp = NULL;
-                if (__atomic_compare_exchange_n(&sigbus_queue[u], &tmp, addr, false,
+                if (__atomic_compare_exchange_n(u, &tmp, addr, false,
                                                 __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) {
                         __atomic_fetch_add(&n_sigbus_queue, 1, __ATOMIC_SEQ_CST);
                         return;
@@ -102,7 +102,7 @@ static void sigbus_handler(int sn, siginfo_t *si, void *data) {
         assert(si);
 
         if (si->si_code != BUS_ADRERR || !si->si_addr) {
-                assert_se(sigaction(SIGBUS, &old_sigaction, NULL) == 0);
+                assert_se(sigaction(SIGBUS, &old_sigaction, NULL) >= 0);
                 propagate_signal(sn, si);
                 return;
         }
@@ -133,7 +133,7 @@ void sigbus_install(void) {
         n_installed++;
 
         if (n_installed == 1)
-                assert_se(sigaction(SIGBUS, &sa, &old_sigaction) == 0);
+                assert_se(sigaction(SIGBUS, &sa, &old_sigaction) >= 0);
 
         return;
 }
@@ -146,7 +146,7 @@ void sigbus_reset(void) {
         n_installed--;
 
         if (n_installed == 0)
-                assert_se(sigaction(SIGBUS, &old_sigaction, NULL) == 0);
+                assert_se(sigaction(SIGBUS, &old_sigaction, NULL) >= 0);
 
         return;
 }