diff options
author | Evgeny Vereshchagin <evvers@ya.ru> | 2016-12-13 10:36:03 +0000 |
---|---|---|
committer | Evgeny Vereshchagin <evvers@ya.ru> | 2016-12-13 12:58:42 +0000 |
commit | fcb2427055bc2e1d8f009ebf3b4d8b1b2bb14faa (patch) | |
tree | 6ea27ead454919df1ba59cd0ff553d5f6a096a38 /src | |
parent | 6916b164642d8bb4938878f4284f8ee5ccf3efd6 (diff) |
core: machine_id_setup overwrites broken machine-id
Diffstat (limited to 'src')
-rw-r--r-- | src/core/machine-id-setup.c | 10 |
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); |