Merge pull request #28359 from keszybz/ret-gather

Add RET_GATHER macro to make continue-but-remember-first-error functions easier
This commit is contained in:
Daan De Meyer
2023-07-28 14:28:35 +02:00
committed by GitHub
30 changed files with 247 additions and 415 deletions
+2 -8
View File
@@ -516,14 +516,8 @@ int bus_track_add_name_many(sd_bus_track *t, char **l) {
/* Continues adding after failure, and returns the first failure. */
STRV_FOREACH(i, l) {
int k;
k = sd_bus_track_add_name(t, *i);
if (k < 0 && r >= 0)
r = k;
}
STRV_FOREACH(i, l)
RET_GATHER(r, sd_bus_track_add_name(t, *i));
return r;
}
+2 -2
View File
@@ -218,8 +218,8 @@ int devnode_acl_all(const char *seat,
k = devnode_acl(n, flush, del, old_uid, add, new_uid);
if (k == -ENOENT)
log_debug("Device %s disappeared while setting ACLs", n);
else if (k < 0 && r == 0)
r = k;
else
RET_GATHER(r, k);
}
return r;
+5 -11
View File
@@ -128,21 +128,15 @@ static int nscd_flush_cache_one(const char *database, usec_t end) {
}
int nscd_flush_cache(char **databases) {
usec_t end;
int r = 0;
/* Tries to invalidate the specified database in nscd. We do this carefully, with a 5s timeout, so that we
* don't block indefinitely on another service. */
/* Tries to invalidate the specified database in nscd. We do this carefully, with a 5s timeout,
* so that we don't block indefinitely on another service. */
end = usec_add(now(CLOCK_MONOTONIC), NSCD_FLUSH_CACHE_TIMEOUT_USEC);
usec_t end = usec_add(now(CLOCK_MONOTONIC), NSCD_FLUSH_CACHE_TIMEOUT_USEC);
STRV_FOREACH(i, databases) {
int k;
k = nscd_flush_cache_one(*i, end);
if (k < 0 && r >= 0)
r = k;
}
STRV_FOREACH(i, databases)
RET_GATHER(r, nscd_flush_cache_one(*i, end));
return r;
}