]> code.citadel.org Git - citadel.git/blobdiff - citadel/sysdep.c
Patches from Matt with slight mod from me to do without strlen. Also modified lprintf...
[citadel.git] / citadel / sysdep.c
index b819acca7eb459af80bbe63e8a10ece9ed837375..94029bc68fead4090dc82b1199eaea7990d52945 100644 (file)
@@ -103,6 +103,7 @@ void DestroyWorkerList(void);
  * lprintf()  ...   Write logging information
  */
 void lprintf(enum LogLevel loglevel, const char *format, ...) {   
+       char *buf;
        va_list arg_ptr;
 
        if (enable_syslog) {
@@ -112,7 +113,9 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) {
        }
 
        /* stderr output code */
-       if (enable_syslog || running_as_daemon) return;
+       if (enable_syslog || running_as_daemon) {
+               return;
+       }
 
        /* if we run in forground and syslog is disabled, log to terminal */
        if (loglevel <= verbosity) { 
@@ -124,24 +127,30 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) {
                /* Promote to time_t; types differ on some OSes (like darwin) */
                unixtime = tv.tv_sec;
                localtime_r(&unixtime, &tim);
+//     begin_critical_section(S_LOG);
+
+               buf = malloc(SIZ+strlen(format));
+
                if (CC->cs_pid != 0) {
-                       fprintf(stderr,
+                       sprintf(buf,
                                "%04d/%02d/%02d %2d:%02d:%02d.%06ld [%3d] ",
                                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);
                } else {
-                       fprintf(stderr,
+                       sprintf(buf,
                                "%04d/%02d/%02d %2d:%02d:%02d.%06ld ",
                                tim.tm_year + 1900, tim.tm_mon + 1,
                                tim.tm_mday, tim.tm_hour, tim.tm_min,
                                tim.tm_sec, (long)tv.tv_usec);
                }
-               va_start(arg_ptr, format);   
-                       vfprintf(stderr, format, arg_ptr);   
+               strcat(buf, format);
+               va_start(arg_ptr, buf);   
+               vfprintf(stderr, buf, arg_ptr);   
                va_end(arg_ptr);   
                fflush(stderr);
+//     end_critical_section(S_LOG);
        }
 }   
 
@@ -162,11 +171,25 @@ static RETSIGTYPE signal_cleanup(int signum) {
        master_cleanup(signum);
 }
 
+
+
+
+void InitialiseSemaphores(void)
+{
+       int i;
+
+       /* Set up a bunch of semaphores to be used for critical sections */
+       for (i=0; i<MAX_SEMAPHORES; ++i) {
+               pthread_mutex_init(&Critters[i], NULL);
+       }
+}
+
+
+
 /*
  * Some initialization stuff...
  */
 void init_sysdep(void) {
-       int i;
        sigset_t set;
 
        /* Avoid vulnerabilities related to FD_SETSIZE if we can. */
@@ -185,11 +208,6 @@ void init_sysdep(void) {
        init_ssl();
 #endif
 
-       /* Set up a bunch of semaphores to be used for critical sections */
-       for (i=0; i<MAX_SEMAPHORES; ++i) {
-               pthread_mutex_init(&Critters[i], NULL);
-       }
-
        /*
         * Set up a place to put thread-specific data.
         * We only need a single pointer per thread - it points to the
@@ -351,7 +369,7 @@ int ig_uds_server(char *sockpath, int queue_len, char **errormessage)
        int s;
        int i;
        int actual_queue_len;
-
+       long ret, ret2;
        actual_queue_len = queue_len;
        if (actual_queue_len < 5) actual_queue_len = 5;
 
@@ -407,7 +425,7 @@ int ig_uds_server(char *sockpath, int queue_len, char **errormessage)
                return(-1);
        }
 
-       chmod(sockpath, 0777);
+       chmod(sockpath, S_ISGID|S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH);
        return(s);
 }
 
@@ -599,6 +617,7 @@ void client_write(char *buf, int nbytes)
                                "client_write(%d bytes) failed: %s (%d)\n",
                                nbytes - bytes_written,
                                strerror(errno), errno);
+                       cit_backtrace();
                        CC->kill_me = 1;
                        return;
                }