summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobert James Kaes <rjkaes@users.sourceforge.net>2002-04-22 19:34:20 +0000
committerRobert James Kaes <rjkaes@users.sourceforge.net>2002-04-22 19:34:20 +0000
commit2ec7a4dd7277ab94ef7821cdc94a437efeee3b39 (patch)
tree74bc37abdd41b3c09c513a008204a067dd5710eb /src
parent60f61c8f0c33f6f33b40e59dba14d4448fa4fb18 (diff)
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 'src')
-rw-r--r--src/log.c64
-rw-r--r--src/log.h7
-rw-r--r--src/tinyproxy.c7
-rw-r--r--src/tinyproxy.h4
4 files changed, 73 insertions, 9 deletions
diff --git a/src/log.c b/src/log.c
index 1a093df..92b5c1f 100644
--- a/src/log.c
+++ b/src/log.c
@@ -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;
+}
diff --git a/src/log.h b/src/log.h
index d7c608c..bd74471 100644
--- a/src/log.h
+++ b/src/log.h
@@ -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