diff --git a/src/avl/avl.c b/src/avl/avl.c index 87be04c9..5d01dce2 100644 --- a/src/avl/avl.c +++ b/src/avl/avl.c @@ -22,7 +22,7 @@ * */ -/* $Id: avl.c,v 1.10 2003/12/04 16:27:30 oddsock Exp $ */ +/* $Id: avl.c,v 1.11 2004/01/27 02:16:25 karl Exp $ */ /* * This is a fairly straightfoward translation of a prototype @@ -89,7 +89,8 @@ avl_tree_free_helper (avl_node * node, avl_free_key_fun_type free_key_fun) if (node->left) { avl_tree_free_helper (node->left, free_key_fun); } - free_key_fun (node->key); + if (free_key_fun) + free_key_fun (node->key); if (node->right) { avl_tree_free_helper (node->right, free_key_fun); } @@ -446,7 +447,8 @@ int avl_delete(avl_tree *tree, void *key, avl_free_key_fun_type free_key_fun) p = x->parent; /* return the key and node to storage */ - free_key_fun (x->key); + if (free_key_fun) + free_key_fun (x->key); thread_rwlock_destroy (&x->rwlock); free (x); diff --git a/src/logging.c b/src/logging.c index c38671ab..cb613687 100644 --- a/src/logging.c +++ b/src/logging.c @@ -16,6 +16,7 @@ #include "os.h" #include "cfgfile.h" #include "logging.h" +#include "util.h" #ifdef _WIN32 #define snprintf _snprintf @@ -44,33 +45,43 @@ void logging_access(client_t *client) { char datebuf[128]; char reqbuf[1024]; - struct tm *thetime; + struct tm thetime; time_t now; time_t stayed; + char *referrer, *user_agent; now = time(NULL); /* build the data */ - /* TODO: localtime is not threadsafe on all platforms - ** we should probably use localtime_r if it's available - */ - PROTECT_CODE(thetime = localtime(&now); strftime(datebuf, 128, LOGGING_FORMAT_CLF, thetime)) + localtime_r (&now, &thetime); + strftime (datebuf, sizeof(datebuf), LOGGING_FORMAT_CLF, &thetime); /* build the request */ - snprintf(reqbuf, 1024, "%s %s %s/%s", httpp_getvar(client->parser, HTTPP_VAR_REQ_TYPE), httpp_getvar(client->parser, HTTPP_VAR_URI), - httpp_getvar(client->parser, HTTPP_VAR_PROTOCOL), httpp_getvar(client->parser, HTTPP_VAR_VERSION)); + snprintf (reqbuf, sizeof(reqbuf), "%s %s %s/%s", + httpp_getvar (client->parser, HTTPP_VAR_REQ_TYPE), + httpp_getvar (client->parser, HTTPP_VAR_URI), + httpp_getvar (client->parser, HTTPP_VAR_PROTOCOL), + httpp_getvar (client->parser, HTTPP_VAR_VERSION)); stayed = now - client->con->con_time; - log_write_direct(accesslog, "%s - - [%s] \"%s\" %d %lld \"%s\" \"%s\" %d", + referrer = httpp_getvar (client->parser, "referer"); + if (referrer == NULL) + referrer = "-"; + + user_agent = httpp_getvar (client->parser, "user-agent"); + if (user_agent == NULL) + user_agent = "-"; + + log_write_direct (accesslog, "%s - - [%s] \"%s\" %d %lld \"%s\" \"%s\" %u", client->con->ip, datebuf, reqbuf, client->respcode, client->con->sent_bytes, - (httpp_getvar(client->parser, "referer") != NULL) ? httpp_getvar(client->parser, "referer") : "-", - (httpp_getvar(client->parser, "user-agent") != NULL) ? httpp_getvar(client->parser, "user-agent") : "-", - (int)stayed); + referrer, + user_agent, + stayed); } diff --git a/src/os.h b/src/os.h index e6f67565..565d902e 100644 --- a/src/os.h +++ b/src/os.h @@ -15,4 +15,4 @@ #define PATH_SEPARATOR "/" #endif -#endif /* __GLOBALS_H__ */ +#endif /* __OS_H__ */ diff --git a/src/stats.c b/src/stats.c index 57283059..43d8da91 100644 --- a/src/stats.c +++ b/src/stats.c @@ -455,8 +455,6 @@ static void *_stats_thread(void *arg) /* wake the other threads so they can shut down cleanly */ thread_cond_broadcast(&_event_signal_cond); - thread_exit(0); - return NULL; } @@ -652,8 +650,6 @@ void *stats_connection(void *arg) _stats_threads--; thread_mutex_unlock(&_stats_mutex); - thread_exit(0); - return NULL; } diff --git a/src/thread/thread.c b/src/thread/thread.c index 5b5c51eb..9bccdb1e 100644 --- a/src/thread/thread.c +++ b/src/thread/thread.c @@ -222,7 +222,6 @@ static void _block_signals(void) /* These ones we want */ sigdelset(&ss, SIGKILL); sigdelset(&ss, SIGSTOP); - sigdelset(&ss, SIGTERM); sigdelset(&ss, SIGSEGV); sigdelset(&ss, SIGBUS); if (pthread_sigmask(SIG_BLOCK, &ss, NULL) != 0) { @@ -250,6 +249,7 @@ static void _catch_signals(void) sigaddset(&ss, SIGCHLD); sigaddset(&ss, SIGINT); sigaddset(&ss, SIGPIPE); + sigaddset(&ss, SIGTERM); if (pthread_sigmask(SIG_UNBLOCK, &ss, NULL) != 0) { #ifdef THREAD_DEBUG