[xiph-cvs] cvs commit: thread thread.c

Karl Heyes karl at xiph.org
Mon Jan 26 18:16:25 PST 2004



karl        04/01/26 21:16:25

  Modified:    src      logging.c os.h stats.c
               .        avl.c
               .        thread.c
  Log:
  minor cleanups, and only have one thread responding to TERM

Revision  Changes    Path
1.8       +22 -11    icecast/src/logging.c

Index: logging.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/logging.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- logging.c	21 Jul 2003 01:58:54 -0000	1.7
+++ logging.c	27 Jan 2004 02:16:23 -0000	1.8
@@ -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 @@
 {
     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);
 }
 
 

<p><p>1.5       +1 -1      icecast/src/os.h

Index: os.h
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/os.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- os.h	1 Dec 2002 02:10:25 -0000	1.4
+++ os.h	27 Jan 2004 02:16:24 -0000	1.5
@@ -15,4 +15,4 @@
 #define PATH_SEPARATOR "/"
 #endif
 
-#endif  /* __GLOBALS_H__ */
+#endif  /* __OS_H__ */

<p><p>1.31      +0 -4      icecast/src/stats.c

Index: stats.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/stats.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- stats.c	4 Dec 2003 16:25:28 -0000	1.30
+++ stats.c	27 Jan 2004 02:16:24 -0000	1.31
@@ -455,8 +455,6 @@
     /* 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 @@
     _stats_threads--;
     thread_mutex_unlock(&_stats_mutex);
 
-    thread_exit(0);
-    
     return NULL;
 }
 

<p><p>1.11      +5 -3      avl/avl.c

Index: avl.c
===================================================================
RCS file: /usr/local/cvsroot/avl/avl.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- avl.c	4 Dec 2003 16:27:30 -0000	1.10
+++ avl.c	27 Jan 2004 02:16:25 -0000	1.11
@@ -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 @@
   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 @@
   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);
 

<p><p>1.27      +1 -1      thread/thread.c

Index: thread.c
===================================================================
RCS file: /usr/local/cvsroot/thread/thread.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- thread.c	27 Jul 2003 18:19:31 -0000	1.26
+++ thread.c	27 Jan 2004 02:16:25 -0000	1.27
@@ -222,7 +222,6 @@
         /* 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 @@
         sigaddset(&ss, SIGCHLD);
         sigaddset(&ss, SIGINT);
         sigaddset(&ss, SIGPIPE);
+        sigaddset(&ss, SIGTERM);
 
         if (pthread_sigmask(SIG_UNBLOCK, &ss, NULL) != 0) {
 #ifdef THREAD_DEBUG

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list