diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-02-14 11:17:32 +0100 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-02-14 12:51:40 +0100 |
commit | 1eb86ddde4f36165a99732b53cc97cef1acc3aa7 (patch) | |
tree | 6613158bdbd6f893e81ab4f2277ab7cef6e4faa5 | |
parent | da486c30fe6ed781d5cb865633b937c4edd93857 (diff) | |
download | systemd-1eb86ddde4f36165a99732b53cc97cef1acc3aa7.tar.gz |
repart: Create temporary root directory using var_tmp_dir()
This allows users to override the directory used with environment
variables.
-rw-r--r-- | src/partition/repart.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/partition/repart.c b/src/partition/repart.c index 43f25e7e59..93dfb5fb3e 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) |