]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
*: convert amenable fdopendir() calls to take_fdopendir()
authorVito Caputo <vcaputo@pengaru.com>
Tue, 31 Mar 2020 09:00:44 +0000 (02:00 -0700)
committerVito Caputo <vcaputo@pengaru.com>
Tue, 31 Mar 2020 13:48:03 +0000 (06:48 -0700)
Some fdopendir() calls remain where safe_close() is manually
performed, those could be simplified as well by converting to
use the _cleanup_close_ machinery, but makes things less trivial
to review so left for a future cleanup.

src/basic/copy.c
src/basic/stat-util.c
src/nspawn/nspawn-patch-uid.c

index 97d566c5b936b250c0bc7693f58d567de982c95d..b384010ae321d1a74ef09ae368977ac595a1e4d6 100644 (file)
@@ -15,6 +15,7 @@
 #include "copy.h"
 #include "dirent-util.h"
 #include "fd-util.h"
+#include "fileio.h"
 #include "fs-util.h"
 #include "io-util.h"
 #include "macro.h"
@@ -569,10 +570,9 @@ static int fd_copy_directory(
         if (fdf < 0)
                 return -errno;
 
-        d = fdopendir(fdf);
+        d = take_fdopendir(&fdf);
         if (!d)
                 return -errno;
-        fdf = -1;
 
         exists = false;
         if (copy_flags & COPY_MERGE_EMPTY) {
index 8ef90e96b7e38fdb39b78b8cd2a392b30e92205f..5412ccbf7df978cc2de5f563e01aef3ef64518be 100644 (file)
@@ -10,6 +10,7 @@
 #include "alloc-util.h"
 #include "dirent-util.h"
 #include "fd-util.h"
+#include "fileio.h"
 #include "fs-util.h"
 #include "macro.h"
 #include "missing_fs.h"
@@ -77,10 +78,9 @@ int dir_is_empty_at(int dir_fd, const char *path) {
         if (fd < 0)
                 return -errno;
 
-        d = fdopendir(fd);
+        d = take_fdopendir(&fd);
         if (!d)
                 return -errno;
-        fd = -1;
 
         FOREACH_DIRENT(de, d, return -errno)
                 return 0;
index fc591e2725387b8f5c3b9866328d043a07c0cf5b..112c3562acea99883c8d15cff7d8dd1bfaf5d0a2 100644 (file)
@@ -8,6 +8,7 @@
 #include "acl-util.h"
 #include "dirent-util.h"
 #include "fd-util.h"
+#include "fileio.h"
 #include "fs-util.h"
 #include "missing_magic.h"
 #include "nspawn-def.h"
@@ -335,12 +336,11 @@ static int recurse_fd(int fd, bool donate_fd, const struct stat *st, uid_t shift
                         donate_fd = true;
                 }
 
-                d = fdopendir(fd);
+                d = take_fdopendir(&fd);
                 if (!d) {
                         r = -errno;
                         goto finish;
                 }
-                fd = -1;
 
                 FOREACH_DIRENT_ALL(de, d, r = -errno; goto finish) {
                         struct stat fst;