]> code.citadel.org Git - citadel.git/blobdiff - citadel/sysdep.c
* Cleaned up some things that generated compiler warnings
[citadel.git] / citadel / sysdep.c
index 33b0db36919deb47a0aaa4911af0ad25217d10d6..d52b920bea8659ee4897e66950fedb766fe050d4 100644 (file)
@@ -42,6 +42,7 @@
 
 #include <limits.h>
 #include <netinet/in.h>
+#include <arpa/inet.h>
 #include <netdb.h>
 #include <sys/un.h>
 #include <string.h>
@@ -95,8 +96,6 @@ time_t last_purge = 0;                                /* Last dead session purge */
 static int num_threads = 0;                    /* Current number of threads */
 int num_sessions = 0;                          /* Current number of sessions */
 
-pthread_t initial_thread;              /* tid for main() thread */
-
 int syslog_facility = (-1);
 
 
@@ -127,13 +126,13 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) {
        }
        else if (loglevel <= verbosity) { 
                struct timeval tv;
-               struct tm *tim;
+               struct tm tim;
                time_t unixtime;
 
                gettimeofday(&tv, NULL);
                /* Promote to time_t; types differ on some OSes (like darwin) */
                unixtime = tv.tv_sec;
-               tim = localtime(&unixtime);
+               localtime_r(&unixtime, &tim);
                /*
                 * Log provides millisecond accuracy.  If you need
                 * microsecond accuracy and your OS supports it, change
@@ -144,33 +143,33 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) {
                        /* Millisecond display */
                        fprintf(stderr,
                                "%04d/%02d/%02d %2d:%02d:%02d.%03ld [%3d] %s",
-                               tim->tm_year + 1900, tim->tm_mon + 1,
-                               tim->tm_mday, tim->tm_hour, tim->tm_min,
-                               tim->tm_sec, (long)tv.tv_usec / 1000,
+                               tim.tm_year + 1900, tim.tm_mon + 1,
+                               tim.tm_mday, tim.tm_hour, tim.tm_min,
+                               tim.tm_sec, (long)tv.tv_usec / 1000,
                                CC->cs_pid, buf);
 #endif
                        /* Microsecond display */
                        fprintf(stderr,
                                "%04d/%02d/%02d %2d:%02d:%02d.%06ld [%3d] %s",
-                               tim->tm_year + 1900, tim->tm_mon + 1,
-                               tim->tm_mday, tim->tm_hour, tim->tm_min,
-                               tim->tm_sec, (long)tv.tv_usec,
+                               tim.tm_year + 1900, tim.tm_mon + 1,
+                               tim.tm_mday, tim.tm_hour, tim.tm_min,
+                               tim.tm_sec, (long)tv.tv_usec,
                                CC->cs_pid, buf);
                } else {
 #if 0
                        /* Millisecond display */
                        fprintf(stderr,
                                "%04d/%02d/%02d %2d:%02d:%02d.%03ld %s",
-                               tim->tm_year + 1900, tim->tm_mon + 1,
-                               tim->tm_mday, tim->tm_hour, tim->tm_min,
-                               tim->tm_sec, (long)tv.tv_usec / 1000, buf);
+                               tim.tm_year + 1900, tim.tm_mon + 1,
+                               tim.tm_mday, tim.tm_hour, tim.tm_min,
+                               tim.tm_sec, (long)tv.tv_usec / 1000, buf);
 #endif
                        /* Microsecond display */
                        fprintf(stderr,
                                "%04d/%02d/%02d %2d:%02d:%02d.%06ld %s",
-                               tim->tm_year + 1900, tim->tm_mon + 1,
-                               tim->tm_mday, tim->tm_hour, tim->tm_min,
-                               tim->tm_sec, (long)tv.tv_usec, buf);
+                               tim.tm_year + 1900, tim.tm_mon + 1,
+                               tim.tm_mday, tim.tm_hour, tim.tm_min,
+                               tim.tm_sec, (long)tv.tv_usec, buf);
                }
                fflush(stderr);
        }
@@ -897,7 +896,7 @@ void *worker_thread(void *arg) {
        struct CitContext *ptr;
        struct CitContext *bind_me = NULL;
        fd_set readfds;
-       int retval;
+       int retval = 0;
        struct CitContext *con= NULL;   /* Temporary context pointer */
        struct ServiceFunctionHook *serviceptr;
        int ssock;                      /* Descriptor for client socket */
@@ -958,9 +957,8 @@ do_select:  force_purge = 0;
                        tv.tv_usec = 0;
                        retval = select(highest + 1, &readfds, NULL, NULL, &tv);
                }
-               else {
-                       break;
-               }
+
+               if (time_to_die) return(NULL);
 
                /* Now figure out who made this select() unblock.
                 * First, check for an error or exit condition.
@@ -1028,10 +1026,6 @@ do_select:       force_purge = 0;
                        }
                }
 
-               if (time_to_die) {
-                       break;
-               }
-
                /* It must be a client socket.  Find a context that has data
                 * waiting on its socket *and* is in the CON_IDLE state.  Any
                 * active sockets other than our chosen one are marked as
@@ -1084,8 +1078,7 @@ SKIP_SELECT:
        }
 
        /* If control reaches this point, the server is shutting down */        
-       --num_threads;
-       return NULL;
+       return(NULL);
 }