diff options
author | Robert James Kaes <rjkaes@users.sourceforge.net> | 2002-04-22 19:34:20 +0000 |
---|---|---|
committer | Robert James Kaes <rjkaes@users.sourceforge.net> | 2002-04-22 19:34:20 +0000 |
commit | 2ec7a4dd7277ab94ef7821cdc94a437efeee3b39 (patch) | |
tree | 74bc37abdd41b3c09c513a008204a067dd5710eb | |
parent | 60f61c8f0c33f6f33b40e59dba14d4448fa4fb18 (diff) | |
download | tinyproxy-2ec7a4dd7277ab94ef7821cdc94a437efeee3b39.tar.gz tinyproxy-2ec7a4dd7277ab94ef7821cdc94a437efeee3b39.zip |
The log_message() function now stores the messages if the configuration
file has not been read yet. The reason for this is that we don't know
where to log the messgaes until _after_ the config file has been
processed.
Diffstat (limited to '')
-rw-r--r-- | src/log.c | 64 | ||||
-rw-r--r-- | src/log.h | 7 | ||||
-rw-r--r-- | src/tinyproxy.c | 7 | ||||
-rw-r--r-- | src/tinyproxy.h | 4 |
4 files changed, 73 insertions, 9 deletions
@@ -1,4 +1,4 @@ -/* $Id: log.c,v 1.16 2001-11-22 00:31:10 rjkaes Exp $ +/* $Id: log.c,v 1.17 2002-04-22 19:34:19 rjkaes Exp $ * * Logs the various messages which tinyproxy produces to either a log file or * the syslog daemon. Not much to it... @@ -19,6 +19,7 @@ #include "tinyproxy.h" +#include "hashmap.h" #include "log.h" static char *syslog_level[] = { @@ -39,13 +40,21 @@ static char *syslog_level[] = { /* * Store the log level setting. */ -static short int log_level = LOG_ERR; +static int log_level = LOG_INFO; + +/* + * Hold a listing of log messages which need to be sent once the log + * file has been established. + * The key is the actual messages (already filled in full), and the value + * is the log level. + */ +static hashmap_t log_message_storage; /* * Set the log level for writing to the log file. */ void -set_log_level(short int level) +set_log_level(int level) { log_level = level; } @@ -54,7 +63,7 @@ set_log_level(short int level) * This routine logs messages to either the log file or the syslog function. */ void -log_message(short int level, char *fmt, ...) +log_message(int level, char *fmt, ...) { va_list args; time_t nowtime; @@ -86,6 +95,30 @@ log_message(short int level, char *fmt, ...) va_start(args, fmt); + /* + * If the config file hasn't been processed, then we need to store + * the messages for later processing. + */ + if (!processed_config_file) { + char string_level[4]; + + if (!log_message_storage) { + log_message_storage = hashmap_create(1); + if (!log_message_storage) + return; + } + + vsnprintf(str, STRING_LENGTH, fmt, args); + snprintf(string_level, 4, "%d", level); + + hashmap_insert(log_message_storage, str, + string_level, strlen(string_level) + 1); + + va_end(args); + + return; + } + #ifdef HAVE_SYSLOG_H if (config.syslog) { # ifdef HAVE_VSYSLOG_H @@ -115,3 +148,26 @@ log_message(short int level, char *fmt, ...) va_end(args); } + +/* + * This needs to send any stored log messages. + */ +void +send_stored_logs(void) +{ + vector_t messages; + char *level; + char *string; + int i; + + messages = hashmap_keys(log_message_storage); + for (i = 0; i < vector_length(messages); i++) { + vector_getentry(messages, i, (void **)&string); + hashmap_search(log_message_storage, string, (void **)&level); + + log_message(atoi(level), string); + } + vector_delete(messages); + hashmap_delete(log_message_storage); + log_message_storage = NULL; +} @@ -1,4 +1,4 @@ -/* $Id: log.h,v 1.8 2001-11-22 00:31:10 rjkaes Exp $ +/* $Id: log.h,v 1.9 2002-04-22 19:34:19 rjkaes Exp $ * * See 'log.c' for a detailed description. * @@ -99,7 +99,8 @@ # define DEBUG2(x, y...) do { } while(0) #endif -extern void log_message(short int level, char *fmt, ...); -extern void set_log_level(short int level); +extern void log_message(int level, char *fmt, ...); +extern void set_log_level(int level); +extern void send_stored_logs(void); #endif diff --git a/src/tinyproxy.c b/src/tinyproxy.c index cf778ff..6f9d9a5 100644 --- a/src/tinyproxy.c +++ b/src/tinyproxy.c @@ -1,4 +1,4 @@ -/* $Id: tinyproxy.c,v 1.27 2002-04-18 17:59:21 rjkaes Exp $ +/* $Id: tinyproxy.c,v 1.28 2002-04-22 19:34:20 rjkaes Exp $ * * The initialise routine. Basically sets up all the initial stuff (logfile, * listening socket, config options, etc.) and then sits there and loops @@ -45,6 +45,8 @@ extern FILE *yyin; struct config_s config; float load = 0.00; bool_t log_rotation_request = FALSE; +char* bind_address = NULL; +bool_t processed_config_file = FALSE; /* * Handle a signal @@ -199,6 +201,7 @@ main(int argc, char **argv) exit(EX_SOFTWARE); } yyparse(); + processed_config_file = TRUE; #if defined(TUNNEL_SUPPORT) && defined(UPSTREAM_SUPPORT) if (config.tunnel_name && config.upstream_name) { @@ -243,6 +246,8 @@ main(int argc, char **argv) log_message(LOG_INFO, PACKAGE " " VERSION " starting..."); + send_stored_logs(); + /* * Set the default values if they were not set in the config file. */ diff --git a/src/tinyproxy.h b/src/tinyproxy.h index 8414612..797c066 100644 --- a/src/tinyproxy.h +++ b/src/tinyproxy.h @@ -1,4 +1,4 @@ -/* $Id: tinyproxy.h,v 1.28 2002-04-18 16:57:06 rjkaes Exp $ +/* $Id: tinyproxy.h,v 1.29 2002-04-22 19:34:20 rjkaes Exp $ * * See 'tinyproxy.c' for a detailed description. * @@ -219,5 +219,7 @@ struct config_s { /* Global Structures used in the program */ extern struct config_s config; extern bool_t log_rotation_request; +extern char* bind_address; +extern bool_t processed_config_file; #endif |