From: Daan De Meyer Date: Tue, 14 Feb 2023 10:17:32 +0000 (+0100) Subject: repart: Create temporary root directory using var_tmp_dir() X-Git-Tag: v254-rc1~1278^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1eb86ddde4f36165a99732b53cc97cef1acc3aa7;p=thirdparty%2Fsystemd.git repart: Create temporary root directory using var_tmp_dir() This allows users to override the directory used with environment variables. --- diff --git a/src/partition/repart.c b/src/partition/repart.c index 43f25e7e59a..93dfb5fb3e8 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -3872,17 +3872,22 @@ static bool partition_needs_populate(Partition *p) { 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 = -EBADF; + const char *vt; int r; assert(ret); - rfd = mkdtemp_open("/var/tmp/repart-XXXXXX", 0, &root); - if (rfd < 0) - return log_error_errno(rfd, "Failed to create temporary directory: %m"); + r = var_tmp_dir(&vt); + if (r < 0) + return log_error_errno(r, "Could not determine temporary directory: %m"); - if (fchmod(rfd, 0755) < 0) - return log_error_errno(errno, "Failed to change mode of temporary directory: %m"); + r = tempfn_random_child(vt, "repart", &root); + if (r < 0) + return log_error_errno(r, "Failed to generate temporary directory: %m"); + + r = mkdir(root, 0755); + if (r < 0) + return log_error_errno(errno, "Failed to create temporary directory: %m"); r = do_copy_files(p, root, denylist); if (r < 0)