diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-07-28 14:28:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-28 14:28:35 +0200 |
commit | 7ccb171c4c7c81b1007428a19eea3696d8068e3e (patch) | |
tree | 240bce7aa699b3cd29d0ca63b1ea2ebf4ad53be5 /src/libsystemd | |
parent | Merge pull request #28335 from ssahani/dhcp4-route-option (diff) | |
parent | network: use RET_GATHER (diff) | |
download | systemd-7ccb171c4c7c81b1007428a19eea3696d8068e3e.tar.xz systemd-7ccb171c4c7c81b1007428a19eea3696d8068e3e.zip |
Merge pull request #28359 from keszybz/ret-gather
Add RET_GATHER macro to make continue-but-remember-first-error functions easier
Diffstat (limited to 'src/libsystemd')
-rw-r--r-- | src/libsystemd/sd-device/device-enumerator.c | 38 | ||||
-rw-r--r-- | src/libsystemd/sd-netlink/netlink-message-nfnl.c | 10 |
2 files changed, 19 insertions, 29 deletions
diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index e072d976d3..766fadd22c 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -613,38 +613,30 @@ static int enumerator_add_parent_devices( sd_device *device, MatchFlag flags) { - int k, r = 0; + int r; assert(enumerator); assert(device); for (;;) { - k = sd_device_get_parent(device, &device); - if (k == -ENOENT) /* Reached the top? */ - break; - if (k < 0) { - r = k; - break; - } + r = sd_device_get_parent(device, &device); + if (r == -ENOENT) /* Reached the top? */ + return 0; + if (r < 0) + return r; - k = test_matches(enumerator, device, flags); - if (k < 0) { - r = k; - break; - } - if (k == 0) + r = test_matches(enumerator, device, flags); + if (r < 0) + return r; + if (r == 0) continue; - k = device_enumerator_add_device(enumerator, device); - if (k < 0) { - r = k; - break; - } - if (k == 0) /* Exists already? Then no need to go further up. */ - break; + r = device_enumerator_add_device(enumerator, device); + if (r < 0) + return r; + if (r == 0) /* Exists already? Then no need to go further up. */ + return 0; } - - return r; } int device_enumerator_add_parent_devices(sd_device_enumerator *enumerator, sd_device *device) { diff --git a/src/libsystemd/sd-netlink/netlink-message-nfnl.c b/src/libsystemd/sd-netlink/netlink-message-nfnl.c index 582f623efe..a8cec2bd8b 100644 --- a/src/libsystemd/sd-netlink/netlink-message-nfnl.c +++ b/src/libsystemd/sd-netlink/netlink-message-nfnl.c @@ -184,7 +184,7 @@ int sd_nfnl_call_batch( _cleanup_free_ sd_netlink_message **replies = NULL; _cleanup_free_ uint32_t *serials = NULL; - int k, r; + int r; assert_return(nfnl, -EINVAL); assert_return(!netlink_pid_changed(nfnl), -ECHILD); @@ -201,11 +201,9 @@ int sd_nfnl_call_batch( if (r < 0) return r; - for (size_t i = 0; i < n_messages; i++) { - k = sd_netlink_read(nfnl, serials[i], usec, ret_messages ? replies + i : NULL); - if (k < 0 && r >= 0) - r = k; - } + for (size_t i = 0; i < n_messages; i++) + RET_GATHER(r, + sd_netlink_read(nfnl, serials[i], usec, ret_messages ? replies + i : NULL)); if (r < 0) return r; |