Skip to content

Commit

Permalink
conmon: fsync the log file
Browse files Browse the repository at this point in the history
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
  • Loading branch information
mrunalp committed Oct 19, 2018
1 parent 241e6ca commit cd06016
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions conmon/conmon.c
Expand Up @@ -156,6 +156,13 @@ static int log_fd = -1;
exit(EXIT_FAILURE); \
} while (0)

#define pwarn(s) \
do { \
fprintf(stderr, "[conmon:w]: %s %s\n", s, strerror(errno)); \
if (opt_syslog) \
syslog(LOG_INFO, "conmon %.20s <pwarn>: %s %s\n", opt_cid, s, strerror(errno)); \
} while (0)

#define nexit(s) \
do { \
fprintf(stderr, "[conmon:e] %s\n", s); \
Expand Down Expand Up @@ -398,6 +405,11 @@ static void reopen_log_file(void)
{
_cleanup_free_ char *opt_log_path_tmp = g_strdup_printf("%s.tmp", opt_log_path);

/* Sync the logs to disk */
if (fsync(log_fd) < 0) {
pwarn("Failed to sync log file on reopen");
}

/* Close the current log_fd */
close(log_fd);

Expand Down Expand Up @@ -1723,6 +1735,13 @@ int main(int argc, char *argv[])
;
}

/* Sync the logs to disk */
if (log_fd > 0) {
if (fsync(log_fd) < 0) {
pwarn("Failed to sync log file before exit");
}
}

int exit_status = -1;
const char *exit_message = NULL;

Expand Down

0 comments on commit cd06016

Please sign in to comment.