We need to ensure file handles have flushed the stream buffer to disk
before calling fsync().
Also remove redundant calls to fsync(), config_write_file() already
takes care of it.
+ if(fflush(f)) {
+ logger(mesh, MESHLINK_ERROR, "Failed to flush file: %s", strerror(errno));
+ meshlink_errno = MESHLINK_ESTORAGE;
+ return false;
+ }
+
if(fsync(fileno(f))) {
logger(mesh, MESHLINK_ERROR, "Failed to sync file: %s\n", strerror(errno));
return false;
if(fsync(fileno(f))) {
logger(mesh, MESHLINK_ERROR, "Failed to sync file: %s\n", strerror(errno));
return false;
- if(fsync(fileno(f))) {
- logger(mesh, MESHLINK_ERROR, "Failed to sync `%s': %s", tmp_path, strerror(errno));
- fclose(f);
- return false;
- }
-
if(fclose(f)) {
logger(mesh, MESHLINK_ERROR, "Failed to close `%s': %s", tmp_path, strerror(errno));
return false;
if(fclose(f)) {
logger(mesh, MESHLINK_ERROR, "Failed to close `%s': %s", tmp_path, strerror(errno));
return false;
- if(fsync(fileno(f))) {
- logger(mesh, MESHLINK_ERROR, "Failed to sync `%s': %s", tmp_path, strerror(errno));
- fclose(f);
- return false;
- }
-
if(rename(tmp_path, path)) {
logger(mesh, MESHLINK_ERROR, "Failed to rename `%s' to `%s': %s", tmp_path, path, strerror(errno));
fclose(f);
if(rename(tmp_path, path)) {
logger(mesh, MESHLINK_ERROR, "Failed to rename `%s' to `%s': %s", tmp_path, path, strerror(errno));
fclose(f);
- if(fsync(fileno(f))) {
- logger(mesh, MESHLINK_ERROR, "Failed to sync `%s': %s", path, strerror(errno));
- fclose(f);
- return false;
- }
-
if(fclose(f)) {
logger(mesh, MESHLINK_ERROR, "Failed to close `%s': %s", path, strerror(errno));
return false;
if(fclose(f)) {
logger(mesh, MESHLINK_ERROR, "Failed to close `%s': %s", path, strerror(errno));
return false;