chiark / gitweb /
Correct error handling for clock_nanosleep().
authorBen Harris <bjh21@bjh21.me.uk>
Sun, 18 Nov 2018 11:46:50 +0000 (11:46 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Sun, 18 Nov 2018 11:46:50 +0000 (11:46 +0000)
It apparently returns its errors rather than setting errno.

clunk.c

diff --git a/clunk.c b/clunk.c
index aebd1db626186efe96465b037689ad82f7c83c56..32d7db78bacccd29e54662d8ca4bc620addddb85 100644 (file)
--- a/clunk.c
+++ b/clunk.c
@@ -1,4 +1,5 @@
 #include <err.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <stdbool.h>
@@ -89,7 +90,9 @@ pulse()
                err(1, "sigprocmask(block)");
        dummy_out(true);
        record_tick();
-       clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
+       errno = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
+       if (errno != 0)
+               err(1, "clock_nanosleep");
        dummy_out(false);
        if (sigprocmask(SIG_SETMASK, &saved_mask, NULL) != 0)
                err(1, "sigprocmask(restore)");
@@ -209,8 +212,9 @@ run()
                /* Choose when next tick will be. */
                ts.tv_nsec = 1000000000 - pulsewidth;
                ts.tv_sec += tick - 1;
-               if (clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, NULL)
-                   != 0)
+               errno = clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME,
+                                       &ts, NULL);
+               if (errno != 0)
                        err(1, "clock_nanosleep");
        }
 }