summaryrefslogtreecommitdiff
path: root/src/firstboot
diff options
context:
space:
mode:
authorAlan Jenkins <alan.christopher.jenkins@gmail.com>2017-08-17 17:09:44 +0100
committerAlan Jenkins <alan.christopher.jenkins@gmail.com>2017-08-17 20:26:36 +0100
commit0675e94ab53237ad27bfba929c7490bdd2215cf1 (patch)
treeffcd2233a70ae8464b000c1b5e8d52304fa160b6 /src/firstboot
parentdce892acef1c5316fb98f7f5ea287bc74f935ca3 (diff)
downloadsystemd-0675e94ab53237ad27bfba929c7490bdd2215cf1.tar.gz
"Don't fear the fsync()"
For files which are vital to boot 1. Avoid opening any window where power loss will zero them out or worse. I know app developers all coded to the ext3 implementation, but the only formal documentation we have says we're broken if we actually rely on it. E.g. * `man mount`, search for `auto_da_alloc`. * http://www.linux-mtd.infradead.org/faq/ubifs.html#L_atomic_change * https://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/ 2. If we tell the kernel we're interested in writing them to disk, it will tell us if that fails. So at minimum, this means we play our part in notifying the user about errors. I refactored error-handling in `udevadm-hwdb` a little. It turns out I did exactly the same as had already been done in the `systemd-hwdb` version, i.e. commit d702dcd.
Diffstat (limited to 'src/firstboot')
-rw-r--r--src/firstboot/firstboot.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c
index b3578d3e16..586674d458 100644
--- a/src/firstboot/firstboot.c
+++ b/src/firstboot/firstboot.c
@@ -411,7 +411,8 @@ static int process_hostname(void) {
return 0;
mkdir_parents(etc_hostname, 0755);
- r = write_string_file(etc_hostname, arg_hostname, WRITE_STRING_FILE_CREATE);
+ r = write_string_file(etc_hostname, arg_hostname,
+ WRITE_STRING_FILE_CREATE | WRITE_STRING_FILE_SYNC);
if (r < 0)
return log_error_errno(r, "Failed to write %s: %m", etc_hostname);
@@ -432,7 +433,8 @@ static int process_machine_id(void) {
return 0;
mkdir_parents(etc_machine_id, 0755);
- r = write_string_file(etc_machine_id, sd_id128_to_string(arg_machine_id, id), WRITE_STRING_FILE_CREATE);
+ r = write_string_file(etc_machine_id, sd_id128_to_string(arg_machine_id, id),
+ WRITE_STRING_FILE_CREATE | WRITE_STRING_FILE_SYNC);
if (r < 0)
return log_error_errno(r, "Failed to write machine id: %m");
@@ -503,7 +505,7 @@ static int write_root_shadow(const char *path, const struct spwd *p) {
if (putspent(p, f) != 0)
return errno > 0 ? -errno : -EIO;
- return fflush_and_check(f);
+ return fflush_sync_and_check(f);
}
static int process_root_password(void) {