Skip to content

Commit

Permalink
machine-id-setup: explicitly fsync() the machine ID after writing
Browse files Browse the repository at this point in the history
As discussed here:

systemd#2619 (comment)

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 systemd#2619.
  • Loading branch information
poettering committed Apr 20, 2016
1 parent 91c20a1 commit 4127cfe
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/core/machine-id-setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4127cfe

Please sign in to comment.