]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fd-util: don't eat up errors in fd_cloexec_many
authorMike Yuan <me@yhndnzj.com>
Fri, 29 Dec 2023 09:57:59 +0000 (17:57 +0800)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 29 Dec 2023 13:26:40 +0000 (14:26 +0100)
Follow-up for ed18c22c989495aab36512f03449222cfcf79aa7

Before this commit, a successful fd_cloexec() call would
discard all previously gathered errors.

src/basic/fd-util.c

index d704c90adedb411c34f7f73a8f241ea0e9c33911..1a279690d245c678b6e11612adb697e52584b6b5 100644 (file)
@@ -187,7 +187,7 @@ int fd_cloexec(int fd, bool cloexec) {
 }
 
 int fd_cloexec_many(const int fds[], size_t n_fds, bool cloexec) {
-        int ret = 0, r;
+        int r = 0;
 
         assert(fds || n_fds == 0);
 
@@ -195,14 +195,13 @@ int fd_cloexec_many(const int fds[], size_t n_fds, bool cloexec) {
                 if (*fd < 0) /* Skip gracefully over already invalidated fds */
                         continue;
 
-                r = fd_cloexec(*fd, cloexec);
-                if (r < 0) /* Continue going, but return first error */
-                        RET_GATHER(ret, r);
-                else
-                        ret = 1; /* report if we did anything */
+                RET_GATHER(r, fd_cloexec(*fd, cloexec));
+
+                if (r >= 0)
+                        r = 1; /* report if we did anything */
         }
 
-        return ret;
+        return r;
 }
 
 static bool fd_in_set(int fd, const int fds[], size_t n_fds) {