]> 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)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 17 May 2025 11:43:20 +0000 (12:43 +0100)
`clock_nanosleep()` returns error codes directly, rather than using
`errno`. Ensure that we use those codes, rather than checking for `<0`.

(cherry picked from commit 81660754981ce66d194df9f1773edd22840f3daa)
(cherry picked from commit b61ef0b632991b6083c1bb19a014f4925629d8f7)

src/basic/time-util.h

index f273770233ad9b6db3b2b177de703f4456ffb598..66fac34bd81b04c621e8df210c3722d9d6f333e1 100644 (file)
@@ -226,8 +226,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