]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/time-util: fix error handling of clock_nanosleep()
authorDavid Rheinsberg <david@readahead.eu>
Mon, 28 Apr 2025 11:13:10 +0000 (13:13 +0200)
committerMike Yuan <me@yhndnzj.com>
Mon, 28 Apr 2025 17:31:16 +0000 (19:31 +0200)
`clock_nanosleep()` returns error codes directly, rather than using
`errno`. Ensure that we use those codes, rather than checking for `<0`.

src/basic/time-util.h

index 14d660ee7e95e50e2cc2788e3aba594798cd7ac9..3f6e3c9f41cea92f1c27875eee782c259e475af4 100644 (file)
@@ -222,8 +222,8 @@ static inline int usleep_safe(usec_t usec) {
         if (usec == 0)
                 return 0;
 
-        // FIXME: use RET_NERRNO() macro here. Currently, this header cannot include errno-util.h.
-        return clock_nanosleep(CLOCK_MONOTONIC, 0, TIMESPEC_STORE(usec), NULL) < 0 ? -errno : 0;
+        /* `clock_nanosleep()` does not use `errno`, but returns positive error codes. */
+        return -clock_nanosleep(CLOCK_MONOTONIC, 0, TIMESPEC_STORE(usec), NULL);
 }
 
 /* The last second we can format is 31. Dec 9999, 1s before midnight, because otherwise we'd enter 5 digit