]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libsystemd: use _NEG_ macros, adjust some comments
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 10 Aug 2023 07:58:28 +0000 (09:58 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 16 Aug 2023 10:52:56 +0000 (12:52 +0200)
No functional change.

src/libsystemd/sd-bus/bus-socket.c
src/libsystemd/sd-bus/sd-bus.c
src/libsystemd/sd-device/sd-device.c
src/libsystemd/sd-journal/journal-file.c
src/libsystemd/sd-netlink/netlink-socket.c

index af16c64745618fe7ffe0d858711fb1b3c8c51d92..cfa5633f23577b1e5271078d77f7a1c60312c726 100644 (file)
@@ -579,11 +579,10 @@ static int bus_socket_read_auth(sd_bus *b) {
                 } else
                         handle_cmsg = true;
         }
-        if (k < 0) {
-                if (ERRNO_IS_TRANSIENT(k))
-                        return 0;
+        if (ERRNO_IS_NEG_TRANSIENT(k))
+                return 0;
+        if (k < 0)
                 return (int) k;
-        }
         if (k == 0) {
                 if (handle_cmsg)
                         cmsg_close_all(&mh); /* paranoia, we shouldn't have gotten any fds on EOF */
@@ -1298,11 +1297,10 @@ int bus_socket_read_message(sd_bus *bus) {
                 } else
                         handle_cmsg = true;
         }
-        if (k < 0) {
-                if (ERRNO_IS_TRANSIENT(k))
-                        return 0;
+        if (ERRNO_IS_NEG_TRANSIENT(k))
+                return 0;
+        if (k < 0)
                 return (int) k;
-        }
         if (k == 0) {
                 if (handle_cmsg)
                         cmsg_close_all(&mh); /* On EOF we shouldn't have gotten an fd, but let's make sure */
@@ -1361,11 +1359,10 @@ int bus_socket_process_opening(sd_bus *b) {
         assert(b->state == BUS_OPENING);
 
         events = fd_wait_for_event(b->output_fd, POLLOUT, 0);
-        if (events < 0) {
-                if (ERRNO_IS_TRANSIENT(events))
-                        return 0;
+        if (ERRNO_IS_NEG_TRANSIENT(events))
+                return 0;
+        if (events < 0)
                 return events;
-        }
         if (!(events & (POLLOUT|POLLERR|POLLHUP)))
                 return 0;
 
index a250e7b81af5c91beaf836e82266fd26fe774d45..ced4466aa6f57d7cd7114a79a225d2f667550018 100644 (file)
@@ -2178,14 +2178,11 @@ _public_ int sd_bus_send(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie) {
                 size_t idx = 0;
 
                 r = bus_write_message(bus, m, &idx);
-                if (r < 0) {
-                        if (ERRNO_IS_DISCONNECT(r)) {
-                                bus_enter_closing(bus);
-                                return -ECONNRESET;
-                        }
-
+                if (ERRNO_IS_NEG_DISCONNECT(r)) {
+                        bus_enter_closing(bus);
+                        return -ECONNRESET;
+                } else if (r < 0)
                         return r;
-                }
 
                 if (idx < BUS_MESSAGE_SIZE(m))  {
                         /* Wasn't fully written. So let's remember how
@@ -2506,11 +2503,10 @@ _public_ int sd_bus_call(
                         left = UINT64_MAX;
 
                 r = bus_poll(bus, true, left);
-                if (r < 0) {
-                        if (ERRNO_IS_TRANSIENT(r))
-                                continue;
+                if (ERRNO_IS_NEG_TRANSIENT(r))
+                        continue;
+                if (r < 0)
                         goto fail;
-                }
                 if (r == 0) {
                         r = -ETIMEDOUT;
                         goto fail;
@@ -3284,13 +3280,11 @@ static int bus_process_internal(sd_bus *bus, sd_bus_message **ret) {
                 assert_not_reached();
         }
 
-        if (r < 0) {
-                if (ERRNO_IS_DISCONNECT(r)) {
-                        bus_enter_closing(bus);
-                        r = 1;
-                } else
-                        return r;
-        }
+        if (ERRNO_IS_NEG_DISCONNECT(r)) {
+                bus_enter_closing(bus);
+                r = 1;
+        } else if (r < 0)
+                return r;
 
         if (ret)
                 *ret = NULL;
@@ -3388,7 +3382,7 @@ _public_ int sd_bus_wait(sd_bus *bus, uint64_t timeout_usec) {
                 return 0;
 
         r = bus_poll(bus, false, timeout_usec);
-        if (r < 0 && ERRNO_IS_TRANSIENT(r))
+        if (ERRNO_IS_NEG_TRANSIENT(r))
                 return 1; /* treat EINTR as success, but let's exit, so that the caller will call back into us soon. */
 
         return r;
@@ -3420,25 +3414,20 @@ _public_ int sd_bus_flush(sd_bus *bus) {
 
         for (;;) {
                 r = dispatch_wqueue(bus);
-                if (r < 0) {
-                        if (ERRNO_IS_DISCONNECT(r)) {
-                                bus_enter_closing(bus);
-                                return -ECONNRESET;
-                        }
-
+                if (ERRNO_IS_NEG_DISCONNECT(r)) {
+                        bus_enter_closing(bus);
+                        return -ECONNRESET;
+                } else if (r < 0)
                         return r;
-                }
 
                 if (bus->wqueue_size <= 0)
                         return 0;
 
                 r = bus_poll(bus, false, UINT64_MAX);
-                if (r < 0) {
-                        if (ERRNO_IS_TRANSIENT(r))
-                                continue;
-
+                if (ERRNO_IS_NEG_TRANSIENT(r))
+                        continue;
+                if (r < 0)
                         return r;
-                }
         }
 }
 
index af39c984d0e518ed09d9e8fd6bf561c825a4191e..97e2e727c0b013d9a2d5eaf078800a043e6c19a8 100644 (file)
@@ -758,14 +758,12 @@ int device_read_uevent_file(sd_device *device) {
         path = strjoina(syspath, "/uevent");
 
         r = read_full_virtual_file(path, &uevent, &uevent_len);
-        if (r < 0) {
+        if (r == -EACCES || ERRNO_IS_NEG_DEVICE_ABSENT(r))
                 /* The uevent files may be write-only, the device may be already removed, or the device
                  * may not have the uevent file. */
-                if (r == -EACCES || ERRNO_IS_DEVICE_ABSENT(r))
-                        return 0;
-
+                return 0;
+        if (r < 0)
                 return log_device_debug_errno(device, r, "sd-device: Failed to read uevent file '%s': %m", path);
-        }
 
         for (size_t i = 0; i < uevent_len; i++)
                 switch (state) {
index 81858f1aa18e225e351390971ce907786bb214cb..06ffa137d41f1c59c390971aeb53313f72af8e99 100644 (file)
@@ -658,12 +658,10 @@ static int journal_file_verify_header(JournalFile *f) {
                 int r;
 
                 r = sd_id128_get_machine(&machine_id);
-                if (r < 0) {
-                        if (!ERRNO_IS_MACHINE_ID_UNSET(r)) /* handle graceful if machine ID is not initialized yet */
-                                return r;
-
+                if (ERRNO_IS_NEG_MACHINE_ID_UNSET(r)) /* Gracefully handle the machine ID not being initialized yet */
                         machine_id = SD_ID128_NULL;
-                }
+                else if (r < 0)
+                        return r;
 
                 if (!sd_id128_equal(machine_id, f->header->machine_id))
                         return log_debug_errno(SYNTHETIC_ERRNO(EHOSTDOWN),
@@ -2508,13 +2506,12 @@ int journal_file_append_entry(
         }
 
         r = sd_id128_get_machine(&_machine_id);
-        if (r < 0) {
-                if (!ERRNO_IS_MACHINE_ID_UNSET(r))
-                        return r;
-
-                /* If the machine ID is not initialized yet, handle gracefully */
+        if (ERRNO_IS_NEG_MACHINE_ID_UNSET(r))
+                /* Gracefully handle the machine ID not being initialized yet */
                 machine_id = NULL;
-        } else
+        else if (r < 0)
+                return r;
+        else
                 machine_id = &_machine_id;
 
 #if HAVE_GCRYPT
index 96162963a75b222e80dd272b115278bc20fc28c2..635867bb585e06bac5763bc6a08e44a7e3de7dc9 100644 (file)
@@ -198,16 +198,14 @@ static int socket_recv_message(int fd, void *buf, size_t buf_size, uint32_t *ret
         assert(peek || (buf && buf_size > 0));
 
         n = recvmsg_safe(fd, &msg, MSG_TRUNC | (peek ? MSG_PEEK : 0));
-        if (n < 0) {
-                if (n == -ENOBUFS)
-                        return log_debug_errno(n, "sd-netlink: kernel receive buffer overrun");
-                if (ERRNO_IS_TRANSIENT(n)) {
-                        if (ret_mcast_group)
-                                *ret_mcast_group = 0;
-                        return 0;
-                }
+        if (n == -ENOBUFS)
+                return log_debug_errno(n, "sd-netlink: kernel receive buffer overrun");
+        else if (ERRNO_IS_NEG_TRANSIENT(n)) {
+                if (ret_mcast_group)
+                        *ret_mcast_group = 0;
+                return 0;
+        } else if (n < 0)
                 return (int) n;
-        }
 
         if (sender.nl.nl_pid != 0) {
                 /* not from the kernel, ignore */