diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-05-23 12:28:55 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2023-05-23 15:09:31 +0200 |
commit | c264ec5f536c9629a24d770694ce50520ac8420b (patch) | |
tree | f646be0045b69f03fd38b67e328f73c3b2049067 /src/partition/repart.c | |
parent | tmpfiles: add --graceful (diff) | |
download | systemd-c264ec5f536c9629a24d770694ce50520ac8420b.tar.xz systemd-c264ec5f536c9629a24d770694ce50520ac8420b.zip |
repart: do not require /var/tmp if not used
If systemd-repart is running sufficiently early, /var/tmp might not be in place
yet. But if there is nothing to minimize, we won't even use it. Let's move the
check right before the first use.
systemd-repart[441]: Device '/' has no dm-crypt/dm-verity device, no need to look for…
systemd-repart[441]: Device /dev/sda opened and locked.
systemd-repart[441]: Sector size of device is 512 bytes. Using grain size of 4096.
systemd-repart[441]: Could not determine temporary directory: No such file or directory
systemd[1]: systemd-repart.service: Child 441 belongs to systemd-repart.service.
systemd[1]: systemd-repart.service: Main process exited, code=exited, status=1/FAILURE
systemd[1]: systemd-repart.service: Failed with result 'exit-code'.
Diffstat (limited to '')
-rw-r--r-- | src/partition/repart.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/partition/repart.c b/src/partition/repart.c index d5d5e2353f..5a2f992e2d 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -5515,15 +5515,11 @@ static int fd_apparent_size(int fd, uint64_t *ret) { } static int context_minimize(Context *context) { - const char *vt; + const char *vt = NULL; int r; assert(context); - r = var_tmp_dir(&vt); - if (r < 0) - return log_error_errno(r, "Could not determine temporary directory: %m"); - LIST_FOREACH(partitions, p, context->partitions) { _cleanup_(rm_rf_physical_and_freep) char *root = NULL; _cleanup_(unlink_and_freep) char *temp = NULL; @@ -5556,6 +5552,12 @@ static int context_minimize(Context *context) { log_info("Pre-populating %s filesystem of partition %s twice to calculate minimal partition size", p->format, strna(hint)); + if (!vt) { + r = var_tmp_dir(&vt); + if (r < 0) + return log_error_errno(r, "Could not determine temporary directory: %m"); + } + r = tempfn_random_child(vt, "repart", &temp); if (r < 0) return log_error_errno(r, "Failed to generate temporary file path: %m"); @@ -5713,6 +5715,12 @@ static int context_minimize(Context *context) { log_info("Pre-populating verity hash data of partition %s to calculate minimal partition size", strna(hint)); + if (!vt) { + r = var_tmp_dir(&vt); + if (r < 0) + return log_error_errno(r, "Could not determine temporary directory: %m"); + } + r = tempfn_random_child(vt, "repart", &temp); if (r < 0) return log_error_errno(r, "Failed to generate temporary file path: %m"); |