diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-08-10 09:58:28 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-08-16 12:52:56 +0200 |
commit | c5ed77b22086e1b1c7cb8d92396cbd936631547e (patch) | |
tree | 36f7b81aad04f796261d9398a433e20be435ef08 /src/libsystemd | |
parent | manager: use _NEG_ macros to reduce indentation, reword comments, drop parens (diff) | |
download | systemd-c5ed77b22086e1b1c7cb8d92396cbd936631547e.tar.xz systemd-c5ed77b22086e1b1c7cb8d92396cbd936631547e.zip |
libsystemd: use _NEG_ macros, adjust some comments
No functional change.
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/sd-bus/bus-socket.c | 21 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/sd-bus.c | 51 | ||||
-rw-r--r-- | src/libsystemd/sd-device/sd-device.c | 8 | ||||
-rw-r--r-- | src/libsystemd/sd-journal/journal-file.c | 19 | ||||
-rw-r--r-- | src/libsystemd/sd-netlink/netlink-socket.c | 16 |
5 files changed, 47 insertions, 68 deletions
diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c index af16c64745..cfa5633f23 100644 --- a/src/libsystemd/sd-bus/bus-socket.c +++ b/src/libsystemd/sd-bus/bus-socket.c @@ -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; diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index a250e7b81a..ced4466aa6 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -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; - } } } diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index af39c984d0..97e2e727c0 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -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) { diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index 81858f1aa1..06ffa137d4 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -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 diff --git a/src/libsystemd/sd-netlink/netlink-socket.c b/src/libsystemd/sd-netlink/netlink-socket.c index 96162963a7..635867bb58 100644 --- a/src/libsystemd/sd-netlink/netlink-socket.c +++ b/src/libsystemd/sd-netlink/netlink-socket.c @@ -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 */ |