]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
*: use _cleanup_close_ with fdopendir() where trivial 15278/head
authorVito Caputo <vcaputo@pengaru.com>
Tue, 31 Mar 2020 09:35:00 +0000 (02:35 -0700)
committerVito Caputo <vcaputo@pengaru.com>
Tue, 31 Mar 2020 13:48:03 +0000 (06:48 -0700)
Also convert these to use take_fdopendir().

src/home/homework-cifs.c
src/journal/sd-journal.c

index 27f298144a0f4af096ddd1c14f820ee04878f8c6..1510031a38a3dfcfaf0d263fb9970f06b8a77568 100644 (file)
@@ -142,7 +142,8 @@ int home_create_cifs(UserRecord *h, UserRecord **ret_home) {
         _cleanup_(home_setup_undo) HomeSetup setup = HOME_SETUP_INIT;
         _cleanup_(user_record_unrefp) UserRecord *new_home = NULL;
         _cleanup_(closedirp) DIR *d = NULL;
-        int r, copy;
+        _cleanup_close_ int copy = -1;
+        int r;
 
         assert(h);
         assert(user_record_storage(h) == USER_CIFS);
@@ -166,11 +167,9 @@ int home_create_cifs(UserRecord *h, UserRecord **ret_home) {
         if (copy < 0)
                 return -errno;
 
-        d = fdopendir(copy);
-        if (!d) {
-                safe_close(copy);
+        d = take_fdopendir(&copy);
+        if (!d)
                 return -errno;
-        }
 
         errno = 0;
         if (readdir_no_dot(d))
index 36f65ad68830432cd70d3cf440ceb261398542a1..a739fa8aafc678c31e28384f541b71212718585e 100644 (file)
@@ -1718,7 +1718,7 @@ static int add_root_directory(sd_journal *j, const char *p, bool missing_ok) {
                         goto fail;
                 }
         } else {
-                int dfd;
+                _cleanup_close_ int dfd = -1;
 
                 /* If there's no path specified, then we use the top-level fd itself. We duplicate the fd here, since
                  * opendir() will take possession of the fd, and close it, which we don't want. */
@@ -1731,10 +1731,9 @@ static int add_root_directory(sd_journal *j, const char *p, bool missing_ok) {
                         goto fail;
                 }
 
-                d = fdopendir(dfd);
+                d = take_fdopendir(&dfd);
                 if (!d) {
                         r = -errno;
-                        safe_close(dfd);
                         goto fail;
                 }