Index: src/child.c
===================================================================
RCS file: /cvsroot/tinyproxy/tinyproxy-devel/src/child.c,v
retrieving revision 1.5
diff -u -u -r1.5 child.c
--- src/child.c	27 Jun 2002 16:29:21 -0000	1.5
+++ src/child.c	4 Sep 2002 21:54:24 -0000
@@ -164,8 +164,11 @@
 	socklen_t clilen;
 
 	cliaddr = safemalloc(addrlen);
-	if (!cliaddr)
+	if (!cliaddr) {
+		log_message(LOG_CRIT,
+			    "Could not allocate memory for child address.");
 		exit(0);
+	}
 
 	ptr->connects = 0;
 
@@ -382,6 +385,8 @@
 
 		/* Handle log rotation if it was requested */
 		if (received_sighup) {
+			truncate_log_file();
+
 #ifdef FILTER_ENABLE
 			if (config.filter) {
 				filter_destroy();
Index: src/daemon.c
===================================================================
RCS file: /cvsroot/tinyproxy/tinyproxy-devel/src/daemon.c,v
retrieving revision 1.1
diff -u -u -r1.1 daemon.c
--- src/daemon.c	23 May 2002 04:39:32 -0000	1.1
+++ src/daemon.c	4 Sep 2002 21:54:24 -0000
@@ -40,9 +40,11 @@
 	chdir("/");
 	umask(077);
 
+#if 0
 	close(0);
 	close(1);
 	close(2);
+#endif
 }
 
 /*
Index: src/log.c
===================================================================
RCS file: /cvsroot/tinyproxy/tinyproxy-devel/src/log.c,v
retrieving revision 1.22
diff -u -u -r1.22 log.c
--- src/log.c	15 Jun 2002 17:37:11 -0000	1.22
+++ src/log.c	4 Sep 2002 21:54:24 -0000
@@ -19,10 +19,10 @@
 
 #include "tinyproxy.h"
 
-#include "hashmap.h"
 #include "heap.h"
 #include "log.h"
 #include "utils.h"
+#include "vector.h"
 
 static char *syslog_level[] = {
 	NULL,
@@ -40,6 +40,11 @@
 #define STRING_LENGTH 800
 
 /*
+ * Global file descriptor for the log file
+ */
+int log_file_fd = -1;
+
+/*
  * Store the log level setting.
  */
 static int log_level = LOG_INFO;
@@ -50,7 +55,36 @@
  * The key is the actual messages (already filled in full), and the value
  * is the log level.
  */
-static hashmap_t log_message_storage;
+static vector_t log_message_storage;
+
+/*
+ * Open the log file and store the file descriptor in a global location.
+ */
+int
+open_log_file(const char* log_file_name)
+{
+	log_file_fd = create_file_safely(log_file_name, FALSE);
+	return log_file_fd;
+}
+
+/*
+ * Close the log file
+ */
+void
+close_log_file(void)
+{
+	close(log_file_fd);
+}
+
+/*
+ * Truncate log file to a zero length.
+ */
+void
+truncate_log_file(void)
+{
+	lseek(log_file_fd, 0, SEEK_SET);
+	ftruncate(log_file_fd, 0);
+}
 
 /*
  * Set the log level for writing to the log file.
@@ -71,9 +105,7 @@
 	time_t nowtime;
 
 	char time_string[TIME_LENGTH];
-#if defined(HAVE_SYSLOG_H) && !defined(HAVE_VSYSLOG_H)
 	char str[STRING_LENGTH];
-#endif
 
 #ifdef NDEBUG
 	/*
@@ -101,19 +133,23 @@
 	 * the messages for later processing.
 	 */
 	if (!processed_config_file) {
-		char string_level[4];
+		char* entry_buffer;
 
 		if (!log_message_storage) {
-			log_message_storage = hashmap_create(1);
+			log_message_storage = vector_create();
 			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);
+		entry_buffer = safemalloc(strlen(str) + 6);
+		if (!entry_buffer)
+			return;
+			
+		sprintf(entry_buffer, "%d %s", level, str);
+		vector_insert(log_message_storage, entry_buffer,
+			      strlen(entry_buffer) + 1);
 
 		va_end(args);
 
@@ -130,23 +166,21 @@
 #  endif
 	} else {
 #endif
-		FILE* log_file;
-		int fd;
-
-		fd = create_file_safely(config.logf_name, FALSE);
-		log_file = fdopen(fd, "w+");
-
 		nowtime = time(NULL);
 		/* Format is month day hour:minute:second (24 time) */
 		strftime(time_string, TIME_LENGTH, "%b %d %H:%M:%S",
 			 localtime(&nowtime));
 
-		fprintf(log_file, "%-9s %s [%ld]: ", syslog_level[level],
-			time_string, (long int) getpid());
-		vfprintf(log_file, fmt, args);
-		fprintf(log_file, "\n");
+		snprintf(str, STRING_LENGTH, "%-9s %s [%ld]: ", syslog_level[level],
+			 time_string, (long int) getpid());
+
+		assert(log_file_fd >= 0);
+
+		write(log_file_fd, str, strlen(str));
+		vsnprintf(str, STRING_LENGTH, fmt, args);
+		write(log_file_fd, str, strlen(str));
+		write(log_file_fd, "\n", 1);
 
-		fclose(log_file);
 #ifdef HAVE_SYSLOG_H
 	}
 #endif
@@ -160,35 +194,32 @@
 void
 send_stored_logs(void)
 {
-	hashmap_iter iter;
-	char *level_string;
 	char *string;
+	char *ptr;
+
 	int level;
 
-	iter = hashmap_first(log_message_storage);
-	if (iter >= 0) {
-		for ( ; !hashmap_is_end(log_message_storage, iter); ++iter) {
-			hashmap_return_entry(log_message_storage,
-					     iter,
-					     &string,
-					     (void **)&level_string);
+	int i;
 
-			level = atoi(level_string);
+	for (i = 0; i < vector_length(log_message_storage); ++i) {
+		vector_getentry(log_message_storage, i, (void **)&string);
+
+		ptr = strchr(string, ' ') + 1;
+		level = atoi(string);
 
 #if NDEBUG
-			if (log_level == LOG_CONN && level == LOG_INFO)
-				continue;
-			else if (log_level == LOG_INFO) {
-				if (level > LOG_INFO && level != LOG_CONN)
-					continue;
-			} else if (level > log_level)
+		if (log_level == LOG_CONN && level == LOG_INFO)
+			continue;
+		else if (log_level == LOG_INFO) {
+			if (level > LOG_INFO && level != LOG_CONN)
 				continue;
+		} else if (level > log_level)
+			continue;
 #endif
 
-			log_message(level, string);
-		}
+		log_message(level, ptr);
 	}
 
-	hashmap_delete(log_message_storage);
+	vector_delete(log_message_storage);
 	log_message_storage = NULL;
 }
Index: src/log.h
===================================================================
RCS file: /cvsroot/tinyproxy/tinyproxy-devel/src/log.h,v
retrieving revision 1.10
diff -u -u -r1.10 log.h
--- src/log.h	26 May 2002 18:55:19 -0000	1.10
+++ src/log.h	4 Sep 2002 21:54:24 -0000
@@ -99,6 +99,10 @@
 # define DEBUG2(x, y...) do { } while(0)
 #endif
 
+extern int open_log_file(const char* file);
+extern void close_log_file(void);
+extern void truncate_log_file(void);
+
 extern void log_message(int level, char *fmt, ...);
 extern void set_log_level(int level);
 extern void send_stored_logs(void);
Index: src/sock.c
===================================================================
RCS file: /cvsroot/tinyproxy/tinyproxy-devel/src/sock.c,v
retrieving revision 1.38
diff -u -u -r1.38 sock.c
--- src/sock.c	31 May 2002 18:08:01 -0000	1.38
+++ src/sock.c	4 Sep 2002 21:54:24 -0000
@@ -152,7 +152,7 @@
  *	- rjkaes
  */
 int
-listen_sock(uint16_t port, socklen_t * addrlen)
+listen_sock(uint16_t port, socklen_t* addrlen)
 {
 	int listenfd;
 	const int on = 1;
Index: src/tinyproxy.c
===================================================================
RCS file: /cvsroot/tinyproxy/tinyproxy-devel/src/tinyproxy.c,v
retrieving revision 1.38
diff -u -u -r1.38 tinyproxy.c
--- src/tinyproxy.c	12 Jul 2002 17:02:02 -0000	1.38
+++ src/tinyproxy.c	4 Sep 2002 21:54:24 -0000
@@ -230,6 +230,13 @@
 				"%s: You MUST set a LogFile in the configuration file.\n",
 				argv[0]);
 			exit(EX_SOFTWARE);
+		} else {
+			if (open_log_file(config.logf_name) < 0) {
+				fprintf(stderr,
+					"%s: Could not create log file.\n",
+					argv[0]);
+				exit(EX_SOFTWARE);
+			}
 		}
 	} else {
 		if (godaemon == TRUE)
@@ -238,6 +245,9 @@
 			openlog("tinyproxy", LOG_PID, LOG_USER);
 	}
 
+	processed_config_file = TRUE;
+	send_stored_logs();
+
 	/*
 	 * Set the default values if they were not set in the config file.
 	 */
@@ -352,9 +362,6 @@
 		exit(EX_SOFTWARE);
 	}
 
-	processed_config_file = TRUE;
-	send_stored_logs();
-
 	/*
 	 * These signals are only for the parent process.
 	 */
@@ -407,6 +414,8 @@
 
 	if (config.syslog)
 		closelog();
+	else
+		close_log_file();
 
 	exit(EX_OK);
 }
