Fixed a problem where log messages could be missed during a rotate.

This commit is contained in:
Robert James Kaes 2001-09-16 05:38:27 +00:00
parent 8df2fba997
commit 4619035cd2

View File

@ -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, * The initialise routine. Basically sets up all the initial stuff (logfile,
* listening socket, config options, etc.) and then sits there and loops * listening socket, config options, etc.) and then sits there and loops
@ -66,7 +66,8 @@ void takesig(int sig)
if (config.logf) { if (config.logf) {
char *rename_file; char *rename_file;
int log_file_fd; int log_file_des;
FILE *old_fd;
rename_file = safemalloc(strlen(config.logf_name) + 5); rename_file = safemalloc(strlen(config.logf_name) + 5);
if (!rename_file) { if (!rename_file) {
@ -79,18 +80,21 @@ void takesig(int sig)
rename(config.logf_name, rename_file); rename(config.logf_name, rename_file);
log_file_fd = create_file_safely(config.logf_name); log_file_des = create_file_safely(config.logf_name);
if (log_file_fd < 0) { if (log_file_des < 0) {
fprintf(stderr, "Could not safely create new log file.\n"); fprintf(stderr, "Could not safely create new log file.\n");
exit(EX_OSERR); exit(EX_OSERR);
} }
fclose(config.logf); old_fd = 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"); fprintf(stderr, "Could not create new log file.\n");
exit(EX_CANTCREAT); exit(EX_CANTCREAT);
} }
fclose(old_fd);
log_message(LOG_NOTICE, "Log file rotated."); log_message(LOG_NOTICE, "Log file rotated.");
safefree(rename_file); safefree(rename_file);