Skip to content

Commit

Permalink
common/logf: Check return value of fflush
Browse files Browse the repository at this point in the history
This commit adds proper checks for the return value of fsync.

Signed-off-by: Felix Wruck <[email protected]>
  • Loading branch information
k0ch4lo committed Feb 20, 2025
1 parent 0fc105d commit f57ae88
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions common/logf.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,12 @@ logf_file_write(logf_prio_t prio, const char *msg, void *data)

logf_file_write_timestamp(data);
fprintf(data, "[%u] %s %s\n", getpid(), prio_str(prio), msg);
fflush(data);

int res = -1;
if (0 != (res = fflush(data))) {
ERROR_ERRNO("Failed to flush log file for PID %d after message %s: %d", getpid(),
msg, res);
}
}

void
Expand All @@ -388,7 +393,12 @@ logf_test_write(logf_prio_t prio, const char *msg, void *data)
return;

fprintf(data, "[%u] %s %s\n", getpid(), prio_str(prio), msg);
fflush(data);

int res = -1;
if (0 != (res = fflush(data))) {
ERROR_ERRNO("Failed to flush log file for PID %d after message %s: %d", getpid(),
msg, res);
}
}

void *
Expand Down

0 comments on commit f57ae88

Please sign in to comment.