From 4619035cd285d913ad22da19567671b34b72c286 Mon Sep 17 00:00:00 2001 From: Robert James Kaes Date: Sun, 16 Sep 2001 05:38:27 +0000 Subject: Fixed a problem where log messages could be missed during a rotate. --- src/tinyproxy.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/tinyproxy.c b/src/tinyproxy.c index 279807b..d350bbd 100644 --- a/src/tinyproxy.c +++ b/src/tinyproxy.c @@ -1,4 +1,4 @@ -/* $Id: tinyproxy.c,v 1.15 2001-09-15 21:29:22 rjkaes Exp $ +/* $Id: tinyproxy.c,v 1.16 2001-09-16 05:38:27 rjkaes Exp $ * * The initialise routine. Basically sets up all the initial stuff (logfile, * listening socket, config options, etc.) and then sits there and loops @@ -66,7 +66,8 @@ void takesig(int sig) if (config.logf) { char *rename_file; - int log_file_fd; + int log_file_des; + FILE *old_fd; rename_file = safemalloc(strlen(config.logf_name) + 5); if (!rename_file) { @@ -79,18 +80,21 @@ void takesig(int sig) rename(config.logf_name, rename_file); - log_file_fd = create_file_safely(config.logf_name); - if (log_file_fd < 0) { + log_file_des = create_file_safely(config.logf_name); + if (log_file_des < 0) { fprintf(stderr, "Could not safely create new log file.\n"); exit(EX_OSERR); } + + old_fd = config.logf; - fclose(config.logf); - if (!(config.logf = fdopen(log_file_fd, "w"))) { + if (!(config.logf = fdopen(log_file_des, "w"))) { fprintf(stderr, "Could not create new log file.\n"); exit(EX_CANTCREAT); } + fclose(old_fd); + log_message(LOG_NOTICE, "Log file rotated."); safefree(rename_file); -- cgit v1.2.3