summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-04-20 17:49:31 +0200
committerLennart Poettering <lennart@poettering.net>2016-04-22 16:06:20 +0200
commitf53d86c9295d9ac20981ca26beb6b83ad1f4296d (patch)
tree2e2788a2de50ff3d43d3bee8e651e93f13f696d8 /src
parent20b1644140c02b436d5efb203f40c9b80a4579a3 (diff)
machine-id-setup: explicitly fsync() the machine ID after writing
As discussed here: https://github.com/systemd/systemd/issues/2619#issuecomment-184670042 Explicitly syncing /etc/machine-id after writing it, is probably a good idea, since it has a strong "commit" character and is generally a one-time thing. Fixes #2619.
Diffstat (limited to 'src')
-rw-r--r--src/core/machine-id-setup.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/core/machine-id-setup.c b/src/core/machine-id-setup.c
index 9de528b6cf..0145fe2894 100644
--- a/src/core/machine-id-setup.c
+++ b/src/core/machine-id-setup.c
@@ -101,14 +101,23 @@ static int read_machine_id(int fd, char id[34]) {
return 0;
}
-static int write_machine_id(int fd, char id[34]) {
+static int write_machine_id(int fd, const char id[34]) {
+ int r;
+
assert(fd >= 0);
assert(id);
if (lseek(fd, 0, SEEK_SET) < 0)
return -errno;
- return loop_write(fd, id, 33, false);
+ r = loop_write(fd, id, 33, false);
+ if (r < 0)
+ return r;
+
+ if (fsync(fd) < 0)
+ return -errno;
+
+ return 0;
}
static int generate_machine_id(char id[34], const char *root) {