"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.
This commit is contained in:
+10
-4
@@ -233,9 +233,15 @@ static int make_backup(const char *target, const char *x) {
|
||||
if (futimens(fileno(dst), ts) < 0)
|
||||
log_warning_errno(errno, "Failed to fix access and modification time of %s: %m", backup);
|
||||
|
||||
if (rename(temp, backup) < 0)
|
||||
r = fflush_sync_and_check(dst);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
|
||||
if (rename(temp, backup) < 0) {
|
||||
r = -errno;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
@@ -532,7 +538,7 @@ static int write_temporary_shadow(const char *shadow_path, FILE **tmpfile, char
|
||||
return errno ? -errno : -EIO;
|
||||
}
|
||||
|
||||
r = fflush_and_check(shadow);
|
||||
r = fflush_sync_and_check(shadow);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -616,7 +622,7 @@ static int write_temporary_group(const char *group_path, FILE **tmpfile, char **
|
||||
group_changed = true;
|
||||
}
|
||||
|
||||
r = fflush_and_check(group);
|
||||
r = fflush_sync_and_check(group);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -693,7 +699,7 @@ static int write_temporary_gshadow(const char * gshadow_path, FILE **tmpfile, ch
|
||||
group_changed = true;
|
||||
}
|
||||
|
||||
r = fflush_and_check(gshadow);
|
||||
r = fflush_sync_and_check(gshadow);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user