Compare commits

..
1 Commits
7 changed files with 62 additions and 106 deletions

No files matched your search

-13
View File
@@ -1,16 +1,3 @@
2002-04-18 Robert James Kaes <rjkaes@flarenet.com>
* src/tinyproxy.c (takesig): Moved the filter_destroy() code out
of the signal handler and placed it inside of main(). Same
reasoning as the rotate_log_files() changes below.
* src/utils.c (rotate_log_files): Moved the log rotation code out
of the signal handler and into it's own function. Also improved
the robustness of the code. Credit to Petr Lampa for suggesting
that system calls in a signal handler is bad magic. Now the
signal handler sets a flag which is responded to inside of
thread_main_loop().
2002-04-17 Robert James Kaes <rjkaes@flarenet.com> 2002-04-17 Robert James Kaes <rjkaes@flarenet.com>
* configure.ac: Added test for pthread_cancel() since it doesn't * configure.ac: Added test for pthread_cancel() since it doesn't
+2 -2
View File
@@ -1,4 +1,4 @@
dnl $Id: configure.ac,v 2.19 2002-04-18 17:04:38 rjkaes Exp $ dnl $Id: configure.ac,v 2.18 2002-04-17 20:56:35 rjkaes Exp $
dnl Devlopers, please strive to achieve this order: dnl Devlopers, please strive to achieve this order:
dnl dnl
@@ -14,7 +14,7 @@ dnl 8. System services
dnl dnl
dnl Read the Autoconf manual for details. dnl Read the Autoconf manual for details.
AC_INIT([tinyproxy], [1.5.0rc3], [rjkaes@users.sourceforge.net]) AC_INIT([tinyproxy], [1.5.0rc2], [rjkaes@users.sourceforge.net])
AC_CONFIG_SRCDIR([src/tinyproxy.c]) AC_CONFIG_SRCDIR([src/tinyproxy.c])
AC_PREREQ(2.52) AC_PREREQ(2.52)
+1 -7
View File
@@ -1,4 +1,4 @@
/* $Id: thread.c,v 1.25 2002-04-18 16:57:06 rjkaes Exp $ /* $Id: thread.c,v 1.24 2002-04-17 20:54:26 rjkaes Exp $
* *
* Handles the creation/destruction of the various threads required for * Handles the creation/destruction of the various threads required for
* processing incoming connections. * processing incoming connections.
@@ -321,12 +321,6 @@ thread_main_loop(void)
SERVER_UNLOCK(); SERVER_UNLOCK();
sleep(5); sleep(5);
/* Handle log rotation if it was requested */
if (log_rotation_request) {
rotate_log_files();
log_rotation_request = FALSE;
}
} }
} }
+55 -9
View File
@@ -1,4 +1,4 @@
/* $Id: tinyproxy.c,v 1.26 2002-04-18 17:04:04 rjkaes Exp $ /* $Id: tinyproxy.c,v 1.24 2002-04-08 21:35:10 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
@@ -44,7 +44,6 @@ extern FILE *yyin;
*/ */
struct config_s config; struct config_s config;
float load = 0.00; float load = 0.00;
bool_t log_rotation_request = FALSE;
/* /*
* Handle a signal * Handle a signal
@@ -54,11 +53,63 @@ takesig(int sig)
{ {
switch (sig) { switch (sig) {
case SIGHUP: case SIGHUP:
log_rotation_request = TRUE; log_message(LOG_NOTICE, "SIGHUP received, cleaning up.");
break;
if (config.logf) {
char *rename_file;
int log_file_des;
FILE *old_fd;
rename_file = safemalloc(strlen(config.logf_name) + 5);
if (!rename_file) {
fprintf(stderr,
"Could not allocate memory in signal handler!\n");
exit(EX_OSERR);
}
strcpy(rename_file, config.logf_name);
strcat(rename_file, ".rot");
rename(config.logf_name, rename_file);
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;
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);
}
#ifdef FILTER_ENABLE
if (config.filter) {
filter_destroy();
filter_init();
}
log_message(LOG_NOTICE, "Re-reading filter file.");
#endif /* FILTER_ENABLE */
log_message(LOG_NOTICE,
"Finished cleaning memory/connections.");
break;
case SIGTERM: case SIGTERM:
#ifdef FILTER_ENABLE
if (config.filter)
filter_destroy();
#endif /* FILTER_ENABLE */
config.quit = TRUE; config.quit = TRUE;
log_message(LOG_INFO, "SIGTERM received.");
break; break;
} }
@@ -378,11 +429,6 @@ main(int argc, char **argv)
thread_main_loop(); thread_main_loop();
#ifdef FILTER_ENABLE
if (config.filter)
filter_destroy();
#endif
log_message(LOG_INFO, "Shutting down."); log_message(LOG_INFO, "Shutting down.");
thread_kill_threads(); thread_kill_threads();
+2 -3
View File
@@ -1,4 +1,4 @@
/* $Id: tinyproxy.h,v 1.28 2002-04-18 16:57:06 rjkaes Exp $ /* $Id: tinyproxy.h,v 1.27 2002-04-09 22:02:05 rjkaes Exp $
* *
* See 'tinyproxy.c' for a detailed description. * See 'tinyproxy.c' for a detailed description.
* *
@@ -184,7 +184,7 @@
/* Make a new type: bool_t */ /* Make a new type: bool_t */
typedef enum { typedef enum {
FALSE = 0, FALSE = 0,
TRUE = 1 TRUE = (!FALSE)
} bool_t; } bool_t;
struct config_s { struct config_s {
@@ -218,6 +218,5 @@ struct config_s {
/* Global Structures used in the program */ /* Global Structures used in the program */
extern struct config_s config; extern struct config_s config;
extern bool_t log_rotation_request;
#endif #endif
+1 -70
View File
@@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.26 2002-04-18 16:57:06 rjkaes Exp $ /* $Id: utils.c,v 1.25 2002-04-16 03:22:16 rjkaes Exp $
* *
* Misc. routines which are used by the various functions to handle strings * Misc. routines which are used by the various functions to handle strings
* and memory allocation and pretty much anything else we can think of. Also, * and memory allocation and pretty much anything else we can think of. Also,
@@ -23,7 +23,6 @@
#include "buffer.h" #include "buffer.h"
#include "conns.h" #include "conns.h"
#include "filter.h"
#include "log.h" #include "log.h"
#include "sock.h" #include "sock.h"
#include "utils.h" #include "utils.h"
@@ -404,71 +403,3 @@ chomp(char *buffer, size_t length)
return chars; return chars;
} }
/*
* Rotate the current log file. This is performed whenever a SIGHUP is
* received.
*/
void
rotate_log_files(void)
{
char* rename_file;
int log_file_des;
FILE *old_fd;
FILE* new_fd;
log_message(LOG_NOTICE, "SIGHUP received, cleaning up.");
#ifdef FILTER_ENABLE
if (config.filter) {
filter_destroy();
filter_init();
}
log_message(LOG_NOTICE, "Re-reading filter file.");
#endif /* FILTER_ENABLE */
if (config.logf) {
rename_file = safemalloc(strlen(config.logf_name) + 5);
if (!rename_file) {
log_message(LOG_CRIT,
"Could not allocate memory when trying to rotate the log file; therefore, the log has not been rotated.");
return;
}
strcpy(rename_file, config.logf_name);
strcat(rename_file, ".rot");
rename(config.logf_name, rename_file);
log_file_des = create_file_safely(config.logf_name);
if (log_file_des < 0) {
log_message(LOG_CRIT,
"Could not properly create the new log file; therefore the log has not been rotated.");
/* Switch the file name back */
rename(rename_file, config.logf_name);
safefree(rename_file);
return;
}
old_fd = config.logf;
if (!(new_fd = fdopen(log_file_des, "w"))) {
log_message(LOG_CRIT,
"Could not create the new log file; therefore, the log has not been rotated.");
/* Switch the file name back */
rename(rename_file, config.logf_name);
safefree(rename_file);
}
config.logf = new_fd;
fclose(old_fd);
log_message(LOG_NOTICE, "Log file rotated.");
safefree(rename_file);
}
log_message(LOG_NOTICE,
"Finished cleaning memory/connections.");
}
+1 -2
View File
@@ -1,4 +1,4 @@
/* $Id: utils.h,v 1.15 2002-04-18 16:57:06 rjkaes Exp $ /* $Id: utils.h,v 1.14 2002-04-15 02:07:27 rjkaes Exp $
* *
* See 'utils.h' for a detailed description. * See 'utils.h' for a detailed description.
* *
@@ -49,7 +49,6 @@ extern size_t strlcpy(char *dst, const char *src, size_t size);
#endif /* HAVE_STRLCPY */ #endif /* HAVE_STRLCPY */
extern size_t chomp(char *buffer, size_t length); extern size_t chomp(char *buffer, size_t length);
extern void rotate_log_files(void);
/* /*
* The following is to allow for better memory checking. * The following is to allow for better memory checking.