]> code.citadel.org Git - citadel.git/blobdiff - webcit/sysdep.c
Fixed bugs related to last three commits
[citadel.git] / webcit / sysdep.c
index 29ac70bcb314ba5db6e841896ad8a30bcef61e70..47487177eb229a369e57f9b1d2a2b396c6d74ee5 100644 (file)
@@ -1,9 +1,7 @@
 /*
- * $Id$
- *
  * WebCit "system dependent" code.
  *
- * Copyright (c) 1996-2010 by the citadel.org team
+ * Copyright (c) 1996-2011 by the citadel.org team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -159,7 +157,7 @@ void worker_entry(void)
        http_new_modules(&Hdr); 
 
        do {
-               /* Only one thread can accept at a time */
+               /* Each worker thread blocks on accept() while waiting for something to do. */
                fail_this_transaction = 0;
                ssock = -1; 
                errno = EAGAIN;
@@ -167,11 +165,7 @@ void worker_entry(void)
                        --num_threads_executing;
                        ssock = accept(msock, NULL, 0);
                        ++num_threads_executing;
-                       lprintf(9, "Thread %u woke up, accept() returned %d %s\n",
-                               pthread_self(),
-                               ssock,
-                               ((ssock >= 0) ? "" : strerror(errno))
-                       );
+                       if (ssock < 0) fail_this_transaction = 1;
                } while ((msock > 0) && (ssock < 0)  && (time_to_die == 0));
 
                if ((msock == -1)||(time_to_die))
@@ -201,13 +195,15 @@ void worker_entry(void)
 
                                ShutDownWebcit();
 
-                               lprintf(2, "master shutdown exiting!.\n");                              
+                               lprintf(2, "master shutdown exiting.\n");                               
                                exit(0);
                        }
                        break;
                }
                if (ssock < 0 ) continue;
 
+               check_thread_pool_size();
+
                /* Now do something. */
                if (msock < 0) {
                        if (ssock > 0) close (ssock);
@@ -267,7 +263,7 @@ void worker_entry(void)
        } while (!time_to_die);
 
        http_destroy_modules(&Hdr);
-       lprintf (1, "bye\n");
+       lprintf (1, "Thread exiting.\n");
        pthread_exit(NULL);
 }
 
@@ -298,7 +294,7 @@ int lprintf(int loglevel, const char *format, ...)
  */
 pid_t current_child;
 void graceful_shutdown_watcher(int signum) {
-       lprintf (1, "bye; shutting down watcher.");
+       lprintf (1, "Watcher thread exiting.\n");
        kill(current_child, signum);
        if (signum != SIGHUP)
                exit(0);
@@ -433,8 +429,6 @@ void spawn_another_worker_thread()
        pthread_attr_t attr;    /* Thread attributes */
        int ret;
 
-       lprintf(3, "Creating a new thread.\n");
-
        ++num_threads_existing;
        ++num_threads_executing;
 
@@ -530,18 +524,18 @@ void drop_root(uid_t UID)
 #endif // HAVE_GETPWUID_R
 
                if (pwp == NULL)
-                       lprintf(CTDL_CRIT, "WARNING: getpwuid(%ld): %s\n"
+                       syslog(LOG_CRIT, "WARNING: getpwuid(%ld): %s\n"
                                "Group IDs will be incorrect.\n", UID,
                                strerror(errno));
                else {
                        initgroups(pw.pw_name, pw.pw_gid);
                        if (setgid(pw.pw_gid))
-                               lprintf(CTDL_CRIT, "setgid(%ld): %s\n", (long)pw.pw_gid,
+                               syslog(LOG_CRIT, "setgid(%ld): %s\n", (long)pw.pw_gid,
                                        strerror(errno));
                }
-               lprintf(CTDL_INFO, "Changing uid to %ld\n", (long)UID);
+               syslog(LOG_INFO, "Changing uid to %ld\n", (long)UID);
                if (setuid(UID) != 0) {
-                       lprintf(CTDL_CRIT, "setuid() failed: %s\n", strerror(errno));
+                       syslog(LOG_CRIT, "setuid() failed: %s\n", strerror(errno));
                }
 #if defined (HAVE_SYS_PRCTL_H) && defined (PR_SET_DUMPABLE)
                prctl(PR_SET_DUMPABLE, 1);