From 003df7454a5f8bc357127ae48d0022cb8d7274ba Mon Sep 17 00:00:00 2001 From: Mukund Sivaraman Date: Wed, 23 Sep 2009 07:18:23 +0530 Subject: Don't ignore retval of write() in log.c --- src/log.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/log.c b/src/log.c index 6f94ab0..5d12c8d 100644 --- a/src/log.c +++ b/src/log.c @@ -109,6 +109,8 @@ void log_message (int level, const char *fmt, ...) char time_string[TIME_LENGTH]; char str[STRING_LENGTH]; + ssize_t ret; + #ifdef NDEBUG /* * Figure out if we should write the message or not. @@ -177,10 +179,25 @@ void log_message (int level, const char *fmt, ...) assert (log_file_fd >= 0); - write (log_file_fd, str, strlen (str)); + ret = write (log_file_fd, str, strlen (str)); + if (ret == -1) { + log_message (LOG_WARNING, + "Could not write to log file"); + } + vsnprintf (str, STRING_LENGTH, fmt, args); - write (log_file_fd, str, strlen (str)); - write (log_file_fd, "\n", 1); + ret = write (log_file_fd, str, strlen (str)); + if (ret == -1) { + log_message (LOG_WARNING, + "Could not write to log file"); + } + + ret = write (log_file_fd, "\n", 1); + if (ret == -1) { + log_message (LOG_WARNING, + "Could not write to log file"); + } + fsync (log_file_fd); #ifdef HAVE_SYSLOG_H -- cgit v1.2.3