diff options
author | Michael Adam <obnox@samba.org> | 2009-12-23 00:24:36 +0100 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2009-12-23 00:31:55 +0100 |
commit | bc1047945272235208fddcda71d8f25e3063e589 (patch) | |
tree | 8be337d953de709b2ce890386b92d101fb9f9628 /src | |
parent | adf4640104d0568b0e5f228fa4657d1e2320df3c (diff) | |
download | tinyproxy-bc1047945272235208fddcda71d8f25e3063e589.tar.gz tinyproxy-bc1047945272235208fddcda71d8f25e3063e589.zip |
log: fix log_message so do only one write before the fsync.
This way the logging from the various child processes does not
get clobbered up. Formerly, the different write portions
(time stamp, message, newline) would get mixed from the
various child processes' log messages.
Michael
Diffstat (limited to 'src')
-rw-r--r-- | src/log.c | 26 |
1 files changed, 13 insertions, 13 deletions
@@ -173,6 +173,8 @@ void log_message (int level, const char *fmt, ...) syslog (level, "%s", str); #endif } else { + char *p; + nowtime = time (NULL); /* Format is month day hour:minute:second (24 time) */ strftime (time_string, TIME_LENGTH, "%b %d %H:%M:%S", @@ -182,22 +184,20 @@ void log_message (int level, const char *fmt, ...) syslog_level[level], time_string, (long int) getpid ()); - assert (log_file_fd >= 0); + /* + * Overwrite the '\0' and leave room for a trailing '\n' + * be added next. + */ + p = str + strlen(str); + vsnprintf (p, STRING_LENGTH - strlen(str) - 1, fmt, args); - ret = write (log_file_fd, str, strlen (str)); - if (ret == -1) { - log_message (LOG_WARNING, - "Could not write to log file"); - } + p = str + strlen(str); + *p = '\n'; + *(p+1) = '\0'; - vsnprintf (str, STRING_LENGTH, fmt, args); - ret = write (log_file_fd, str, strlen (str)); - if (ret == -1) { - log_message (LOG_WARNING, - "Could not write to log file"); - } + assert (log_file_fd >= 0); - ret = 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"); |