X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fsysdep.c;h=0657b81108121af1d1881ab2e9578e32eb029e46;hb=f5c1330914acc193f96892efc191a32ee537dfb5;hp=432966687a7b646fc3e8f5dbcd64dbfbb91b2c0b;hpb=704407b01c6e6aa2ec71420d92158093011dc90f;p=citadel.git diff --git a/webcit/sysdep.c b/webcit/sysdep.c index 432966687..0657b8110 100644 --- a/webcit/sysdep.c +++ b/webcit/sysdep.c @@ -1,16 +1,23 @@ /* - * $Id$ + * WebCit "system dependent" code. * - * Citadel "system dependent" stuff. - * See copyright.txt for copyright information. + * Copyright (c) 1996-2010 by the citadel.org team * - * Here's where we (hopefully) have most parts of the Citadel server that - * would need to be altered to run the server in a non-POSIX environment. - * - * If we ever port to a different platform and either have multiple - * variants of this file or simply load it up with #ifdefs. + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + #include "sysdep.h" #include #include @@ -150,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; @@ -158,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)) @@ -192,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); @@ -258,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); } @@ -289,15 +294,13 @@ 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); } - - /* * Shut us down the regular way. * signum is the signal we want to forward @@ -416,6 +419,7 @@ void start_daemon(char *pid_file) exit(WEXITSTATUS(status)); } + /* * Spawn an additional worker thread into the pool. */ @@ -425,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; @@ -439,15 +441,12 @@ void spawn_another_worker_thread() * otherwise the MIME parser crashes on FreeBSD. */ if ((ret = pthread_attr_setstacksize(&attr, 1024 * 1024))) { - lprintf(1, "pthread_attr_setstacksize: %s\n", - strerror(ret)); + lprintf(1, "pthread_attr_setstacksize: %s\n", strerror(ret)); pthread_attr_destroy(&attr); } /* now create the thread */ - if (pthread_create(&SessThread, &attr, - (void *(*)(void *)) worker_entry, NULL) - != 0) { + if (pthread_create(&SessThread, &attr, (void *(*)(void *)) worker_entry, NULL) != 0) { lprintf(1, "Can't create thread: %s\n", strerror(errno)); } @@ -503,6 +502,7 @@ webcit_calc_dirs_n_files(int relh, const char *basedir, int home, char *webcitdi perror("chdir"); } } + void drop_root(uid_t UID) { struct passwd pw, *pwp = NULL;