]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: Use fd based operations in partition_populate_directory()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 21 Nov 2022 10:10:34 +0000 (11:10 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 21 Nov 2022 10:47:13 +0000 (11:47 +0100)
src/partition/repart.c

index 9a6bbdfb32f068e1e2d55e5c60703973e0f52c7f..5bae5542585ae6223b520d173d26c17dd490766b 100644 (file)
@@ -3782,6 +3782,7 @@ static int do_make_directories(Partition *p, const char *root) {
 
 static int partition_populate_directory(Partition *p, const Set *denylist, char **ret) {
         _cleanup_(rm_rf_physical_and_freep) char *root = NULL;
+        _cleanup_close_ int rfd = -1;
         int r;
 
         assert(ret);
@@ -3791,11 +3792,11 @@ static int partition_populate_directory(Partition *p, const Set *denylist, char
                 return 0;
         }
 
-        r = mkdtemp_malloc("/var/tmp/repart-XXXXXX", &root);
-        if (r < 0)
-                return log_error_errno(r, "Failed to create temporary directory: %m");
+        rfd = mkdtemp_open("/var/tmp/repart-XXXXXX", 0, &root);
+        if (rfd < 0)
+                return log_error_errno(rfd, "Failed to create temporary directory: %m");
 
-        if (chmod(root, 0755) < 0)
+        if (fchmod(rfd, 0755) < 0)
                 return log_error_errno(errno, "Failed to change mode of temporary directory: %m");
 
         /* Make sure everything is owned by the user running repart so that make_filesystem() can map the