diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-16 18:35:35 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-16 18:35:35 +0000 |
| commit | b76166f7e057162f604efe713e5d6e2bdc1a3b38 (patch) | |
| tree | a4ed6144297f77adab0eef550d4c7ea502dc4431 | |
| parent | 9f9e220ff9ea6b3695e13c9ed53df2a09eb5d1ba (diff) | |
util/nvmutil: loop EINTR on fsync
this improves reliability, making it more
likely that data actually gets synced,
since fsync can return -1 with EINTR,
indicating that a re-try should be
attempted.
Signed-off-by: Leah Rowe <leah@libreboot.org>
| -rw-r--r-- | util/nvmutil/nvmutil.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index e54197b5..91095c18 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -484,6 +484,7 @@ int x_try_fdpath(const char *prefix, int fd, mode_t mode); unsigned long x_conv_fd(char *buf, unsigned long n); +int x_i_fsync(int fd); /* * Sizes in bytes: @@ -1116,7 +1117,7 @@ copy_gbe(void) * fsync tmp gbe file, because we will compare * its contents to what was read (for safety) */ - if (fsync(tmp_fd) == -1) + if (x_i_fsync(tmp_fd) == -1) err(errno, "%s: fsync (tmpfile copy)", tname); r = rw_file_exact(tmp_fd, bufcmp, gbe_file_size, @@ -1810,7 +1811,7 @@ write_to_gbe_bin(void) * We may otherwise read from * cache, so we must sync. */ - if (fsync(tmp_fd) == -1) + if (x_i_fsync(tmp_fd) == -1) err(errno, "%s: fsync (pre-verification)", tname); @@ -2049,7 +2050,7 @@ gbe_mv(void) if (r < 0) goto ret_gbe_mv; - if (fsync(dest_fd) == -1) + if (x_i_fsync(dest_fd) == -1) goto ret_gbe_mv; if (x_i_close(dest_fd) == -1) @@ -2165,7 +2166,7 @@ fsync_dir(const char *path) } /* sync file on disk */ - if (fsync(dfd) == -1) + if (x_i_fsync(dfd) == -1) goto err_fsync_dir; if (x_i_close(dfd) == -1) @@ -3104,7 +3105,7 @@ x_i_rename(const char *src, const char *dst) return -1; } - fsync(dfd); + x_i_fsync(dfd); x_i_close(sfd); x_i_close(dfd); @@ -3233,3 +3234,15 @@ x_conv_fd(char *buf, unsigned long n) return j; } + +int +x_i_fsync(int fd) +{ + int r; + + do { + r = fsync(fd); + } while (r == -1 && errno == EINTR); + + return r; +} |
