about summary refs log tree commit homepage
path: root/sig.c
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-03-09 20:22:23 +0000
committerEric Wong <e@80x24.org>2015-03-09 20:39:10 +0000
commitc659acbb8d7a6b0c8098646981124a47f15cceae (patch)
tree41667f3f21e4870cbfed41f89944921637779134 /sig.c
parent1a7f32d0d8a48b9f26f595d0fa9f5db0c657bc3a (diff)
downloadcmogstored-c659acbb8d7a6b0c8098646981124a47f15cceae.tar.gz
During the initial device scan, it is possible for the waiter to be
interrupted while awaiting cancellation.  We must account for this
on all platforms regardless of whether pselect or ppoll is used.

Reported-by: Mykola Golub <trociny@FreeBSD.org>
Diffstat (limited to 'sig.c')
-rw-r--r--sig.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/sig.c b/sig.c
index c04117a..cfbffc2 100644
--- a/sig.c
+++ b/sig.c
@@ -32,23 +32,33 @@ void mog_intr_enable(void)
  * would increase the size of the executable
  */
 #ifdef HAVE_PPOLL
-static void sleeper(struct timespec *tsp, const sigset_t *sigmask)
+static int sleeper(struct timespec *tsp, const sigset_t *sigmask)
 {
-        if (ppoll(NULL, 0, tsp, sigmask) < 0)
-                assert((errno == EINTR || errno == ENOMEM) &&
+        int err = 0;
+
+        if (ppoll(NULL, 0, tsp, sigmask) < 0) {
+                err = errno;
+                assert((err == EINTR || err == ENOMEM) &&
                        "BUG in ppoll usage");
+        }
+        return err;
 }
 #else /* PSELECT */
-static void sleeper(struct timespec *tsp, const sigset_t *sigmask)
+static int sleeper(struct timespec *tsp, const sigset_t *sigmask)
 {
-        if (pselect(0, NULL, NULL, NULL, tsp, sigmask) < 0)
-                assert((errno == EINTR || errno == ENOMEM) &&
+        int err = 0;
+
+        if (pselect(0, NULL, NULL, NULL, tsp, sigmask) < 0) {
+                err = errno;
+                assert((err == EINTR || err == ENOMEM) &&
                        "BUG in pselect usage");
+        }
+        return err;
 }
 #endif /* PSELECT */
 
 /* thread-safe, interruptible sleep, negative seconds -> sleep forever */
-void mog_sleep(long seconds)
+int mog_sleep(long seconds)
 {
         struct timespec ts;
         struct timespec *tsp;
@@ -61,5 +71,5 @@ void mog_sleep(long seconds)
                 tsp = &ts;
         }
 
-        sleeper(tsp, &mog_emptyset);
+        return sleeper(tsp, &mog_emptyset);
 }