summaryrefslogtreecommitdiff
path: root/src/core/machine-id-setup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/machine-id-setup.c')
-rw-r--r--src/core/machine-id-setup.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c
index c83bb561c7..df3cc74b98 100644
--- a/src/core/machine-id-setup.c
+++ b/src/core/machine-id-setup.c
@@ -146,14 +146,18 @@ int machine_id_setup(const char *root, sd_id128_t machine_id, sd_id128_t *ret) {
r = generate_machine_id(root, &machine_id);
if (r < 0)
return r;
+ }
+ if (writable) {
if (lseek(fd, 0, SEEK_SET) == (off_t) -1)
- return log_error_errno(errno, "Failed to seek: %m");
- }
+ return log_error_errno(errno, "Failed to seek %s: %m", etc_machine_id);
+
+ if (ftruncate(fd, 0) < 0)
+ return log_error_errno(errno, "Failed to truncate %s: %m", etc_machine_id);
- if (writable)
if (id128_write_fd(fd, ID128_PLAIN, machine_id, true) >= 0)
goto finish;
+ }
fd = safe_close(fd);