* Removed all of the thread cancellation cruft that is no longer necessary
authorArt Cancro <ajc@citadel.org>
Thu, 28 Oct 1999 05:08:50 +0000 (05:08 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 28 Oct 1999 05:08:50 +0000 (05:08 +0000)
* Moved the now non-system-dependent RemoveContext() out of sysdep.c (now
  it's part of cleanup() in citserver.c)
* Removed all references to pthread_* from all modules except sysdep.c

27 files changed:
citadel/ChangeLog
citadel/citserver.c
citadel/citserver.h
citadel/control.c
citadel/database.c
citadel/dynloader.c
citadel/file_ops.c
citadel/housekeeping.c
citadel/html.c
citadel/locate_host.c
citadel/logging.c
citadel/mime_parser.c
citadel/msgbase.c
citadel/policy.c
citadel/room_ops.c
citadel/serv_chat.c
citadel/serv_expire.c
citadel/serv_icq.c
citadel/serv_test.c
citadel/serv_upgrade.c
citadel/serv_vcard.c
citadel/server.h
citadel/support.c
citadel/sysconfig.h
citadel/sysdep.c
citadel/sysdep_decls.h
citadel/user_ops.c

index 03fd32230ad4041241498b8044addae71a8939d4..7069b2c48edee89691a20448d97fa276380c4c5b 100644 (file)
@@ -1,4 +1,10 @@
 $Log$
+Revision 1.400  1999/10/28 05:08:49  ajc
+* Removed all of the thread cancellation cruft that is no longer necessary
+* Moved the now non-system-dependent RemoveContext() out of sysdep.c (now
+  it's part of cleanup() in citserver.c)
+* Removed all references to pthread_* from all modules except sysdep.c
+
 Revision 1.399  1999/10/28 03:20:17  ajc
 * Fixed the problem of worker threads waking up prematurely.
 * 'QUIT'-terminated sessions now exit properly.  Still need to fix code for
@@ -1374,3 +1380,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
+
index 0e5c9e90856aebed5bd2d4ddf7861e8d55cc9a59..c9e9c1af3059f44dfe4d0cb3c05d8bf58e1486b6 100644 (file)
@@ -10,9 +10,6 @@
 #include <string.h>
 #include <errno.h>
 #include <limits.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include <syslog.h>
 #include <dlfcn.h>
 #include <netdb.h>
@@ -116,34 +113,72 @@ void deallocate_user_data(struct CitContext *con)
 
 
 /*
- * Gracefully terminate the session and thread.
- * (This is called as a cleanup handler by the thread library.)
- *
- * All NON-system-dependent stuff is done in this function.
- * System-dependent session/thread cleanup is in cleanup() in sysdep.c
+ * Gracefully terminate a session which is marked as CON_DYING.
  */
-void cleanup(int exit_code)
+void cleanup(struct CitContext *con)
 {
-       lprintf(9, "cleanup(%d) called\n", exit_code);
+       struct CitContext *ptr = NULL;
+       struct CitContext *ToFree = NULL;
+
+       lprintf(9, "cleanup() called\n");
+       if (con==NULL) {
+               lprintf(5, "WARNING: cleanup() called with NULL!\n");
+               return;
+               }
 
-       lprintf(7, "Calling logout(%d)\n", CC->cs_pid);
-       logout(CC);
+       lprintf(7, "Calling logout(%d)\n", con->cs_pid);
+       logout(con);
 
-       rec_log(CL_TERMINATE,CC->curr_user);
-       unlink(CC->temp);
-       lprintf(3, "citserver[%3d]: ended.\n",CC->cs_pid);
+       rec_log(CL_TERMINATE, con->curr_user);
+       unlink(con->temp);
+       lprintf(3, "citserver[%3d]: ended.\n", con->cs_pid);
        
        /* Run any cleanup routines registered by loadable modules */
        PerformSessionHooks(EVT_STOP);
 
-       syslog(LOG_NOTICE,"session %d ended", CC->cs_pid);
+       syslog(LOG_NOTICE,"session %d ended", con->cs_pid);
        
        /* Deallocate any user-data attached to this session */
-       deallocate_user_data(CC);
+       deallocate_user_data(con);
+
+       /* And flag the context as in need of being killed.
+        * (Probably done already, but just in case)
+        */
+       con->state = CON_DYING;
+
+       /* delete context */
+
+       lprintf(7, "Removing context\n");
+
+       begin_critical_section(S_SESSION_TABLE);
+       if (ContextList == con) {
+               ToFree = ContextList;
+               ContextList = ContextList->next;
+               }
+       else {
+               for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
+                       if (ptr->next == con) {
+                               ToFree = ptr->next;
+                               ptr->next = ptr->next->next;
+                               }
+                       }
+               }
+       end_critical_section(S_SESSION_TABLE);
+
+       lprintf(7, "Closing socket %d\n", ToFree->client_socket);
+       close(ToFree->client_socket);
+
+        /* Tell the housekeeping thread to check to see if this is the time
+         * to initiate a scheduled shutdown event.
+         */
+        enter_housekeeping_cmd("SCHED_SHUTDOWN");
+
+       /* Free up the memory used by this context */
+       phree(ToFree);
+
+       lprintf(7, "Done with cleanup()\n");
+}
 
-       /* And flag the context as in need of being killed */
-       CC->state = CON_DYING;
-       }
 
 
 /*
@@ -866,7 +901,8 @@ void do_command_loop(void) {
        memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
        if (client_gets(cmdbuf) < 1) {
                lprintf(3, "Client socket is broken.  Ending session.\n");
-               cleanup(EXIT_NULL);
+               CC->state = CON_DYING;
+               return;
        }
        lprintf(5, "citserver[%3d]: %s\n", CC->cs_pid, cmdbuf);
 
@@ -896,7 +932,7 @@ void do_command_loop(void) {
 
        else if (!strncasecmp(cmdbuf,"QUIT",4)) {
                cprintf("%d Goodbye.\n",OK);
-               cleanup(0);
+               CC->state = CON_DYING;
                }
 
        else if (!strncasecmp(cmdbuf,"LOUT",4)) {
index 45ac8d519ca82473b3e5f66063007a7f3915de5c..c206bd72a707fcc543cd433872037e2d22876722 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$ */
 void master_startup (void);
 void master_cleanup (void);
-void cleanup (int);
+void cleanup (struct CitContext *);
 void set_wtmpsupp (char *newtext);
 void set_wtmpsupp_to_current_room(void);
 void cmd_info (void);
index 1455c72c7ba6ef6b16b2f35b91c6849e563633ea..e71c5bbe652a1c66144a509d534ac9440144f57c 100644 (file)
@@ -18,9 +18,6 @@
 #include <string.h>
 #include <errno.h>
 #include <limits.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include <syslog.h>
 #include "citadel.h"
 #include "server.h"
index 674ef3f0b85400d0c21c94747852cc6970799fde..4267b4f8378e3e7a99c4dc9490b0a777412e8ada 100644 (file)
@@ -23,9 +23,6 @@
 #include <ctype.h>
 #include <string.h>
 #include <errno.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #ifdef HAVE_GDBM_H
 #include <gdbm.h>
 #endif
index d11ca6790dcdf701cb98522fe80af0daa4e5112e..259c6d3dd8f54b36004b387b143e9bcf8ceed0cb 100644 (file)
@@ -17,9 +17,6 @@
 #include <dirent.h>
 #include <strings.h>
 #include <syslog.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include <limits.h>
 #include <ctype.h>
 #include "citadel.h"
index 17bc5dcda25a3f284229db96ab5b48728e350b14..dac1dd466a32326ce819da138e18f0ac8d15209b 100644 (file)
@@ -10,9 +10,6 @@
 #include <sys/stat.h>
 #include <time.h>
 #include <limits.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include "citadel.h"
 #include "server.h"
 #include "config.h"
index 726c928158e213e09ce0dc51c0a02f8033eeb9b6..72c1f4aa731e7ae6bc03cf7959435be160b9a9a1 100644 (file)
@@ -20,9 +20,6 @@
 #ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
 #endif
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include "tools.h"
 #include "citadel.h"
 #include "server.h"
index 32065bd4933838e60601aacc1b6d28a2b1265f4e..a4d67929511cc14c55f23d2d13e44f8d686ec165 100644 (file)
@@ -14,9 +14,6 @@
 #include <string.h>
 #include <errno.h>
 #include <limits.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include <syslog.h>
 #include "citadel.h"
 #include "server.h"
index bb1162bb3f4b68a73363ceacfb6a5d15ff9697da..b4f5cdbadcbb810385a4908cc26f82219f4b1a51 100644 (file)
@@ -14,9 +14,6 @@
 #include <limits.h>
 #include <netdb.h>
 #include <string.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include "citadel.h"
 #include "server.h"
 #include "locate_host.h"
index 2b29a6bdf2a8d724042d788b46fb0839d37b48f7..0f5eef2116fd2f6fe7e4c60521225d9e172eb9af 100644 (file)
@@ -13,9 +13,6 @@
 #include <ctype.h>
 #include <string.h>
 #include <errno.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include <syslog.h>
 #include "citadel.h"
 #include "server.h"
index 55f1f4d7ffc8c1d5a4c8d61405fa98952c79749d..ecd54358ee6528eaab579da0df5f2e503e22e7c1 100644 (file)
@@ -21,9 +21,6 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <errno.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include "citadel.h"
 #include "mime_parser.h"
 #include "sysdep_decls.h"
index 5296502a522555db995d0ff46743691d4a7ec212..c959b691bde840f4372efc43467874577ca49165 100644 (file)
@@ -8,9 +8,6 @@
 #include <ctype.h>
 #include <string.h>
 #include <syslog.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include <limits.h>
 #include "citadel.h"
 #include "server.h"
index fa6ec318c7fd861760918f361c7c5602ff7d7cf2..f3df450b5939c58b7166666fc6e57dac1919a946 100644 (file)
@@ -5,9 +5,6 @@
 #include <stdio.h>
 #include <sys/stat.h>
 #include <string.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include <time.h>
 #include <limits.h>
 #include "citadel.h"
index 9dd7ed0ed51b9e4bccb42ad1df99be730e3da38b..b1823ad0953d4c84a6645156b18400dc922ba719 100644 (file)
@@ -5,9 +5,6 @@
 #include <stdio.h>
 #include <sys/stat.h>
 #include <string.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include <time.h>
 #include <limits.h>
 #include <errno.h>
index 5b23aedd376422ad352a241bd06489a4b9dcfb83..88d343e0b8520e843d78bb6deca065cef28e9212 100644 (file)
@@ -19,9 +19,6 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include "citadel.h"
 #include "server.h"
 #include <syslog.h>
index c566bba045f015cff6b8b0d4c2134e854c334066..6ba24723e7f53f11ff5b7278b363555b54387bb7 100644 (file)
@@ -36,9 +36,6 @@
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include "citadel.h"
 #include "server.h"
 #include <syslog.h>
index ae2ecb8c45c7edafdcd38154f1295de79ad57e28..30f3dff55809243dfabc47f8173d36cda19820f8 100644 (file)
@@ -33,9 +33,6 @@
 #include <sys/stat.h>
 #include <limits.h>
 #include "sysdep.h"
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include "citadel.h"
 #include "server.h"
 #include "dynloader.h"
index 7601cf21540c6bab709ec79e613b6e38236a6efa..0d3ce30bce1604542171850c960a77627e295c66 100644 (file)
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include "citadel.h"
 #include "server.h"
-#include <syslog.h>
 #include <time.h>
 #include "sysdep_decls.h"
 #include "citserver.h"
index eeb997b8060d9dec188a4c99f931b2029b32fbd1..1f31a3b59025db76a4c9a8c25ff30b9a88f63575 100644 (file)
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include "citadel.h"
 #include "server.h"
-#include <syslog.h>
 #include <time.h>
 #include "sysdep_decls.h"
 #include "citserver.h"
index 6c3d523ec39fc7f968184c8223cdf1d0d94ce492..40e7727f742adcb56d140d8fbe560625eef82e87 100644 (file)
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include "citadel.h"
 #include "server.h"
-#include <syslog.h>
 #include <time.h>
 #include "sysdep_decls.h"
 #include "citserver.h"
index b693c275dd87d478aac870043574e6f876ab4fd9..72dc9f4d647293c588d6865401d2c172633beb1a 100644 (file)
@@ -1,5 +1,4 @@
 /* $Id$ */
-typedef pthread_t THREAD;
 
 /* Uncomment this if you want to track memory leaks.
  * This incurs some overhead, so don't use it unless you're debugging the code!
index e9d04a078f842617b4ead0ac21ef18c8f32ee08f..cc4ac677b38d87577225bc4ce960296dda3b6bae 100644 (file)
@@ -5,9 +5,6 @@
 #include <ctype.h>
 #include <stdio.h>
 #include <string.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include "citadel.h"
 #include "server.h"
 #include "support.h"
index bda55ed289eed908f74e23c803eb1627ff9c75d8..ff875ee394f2ab4cc52e42c349618b0f62b4c91b 100644 (file)
  * editor installed, and you want to make it the default, set this to 46
  * to make it use your editor by default.
  */
-#define DEFAULT_ENTRY  4
+#define DEFAULT_ENTRY          4
 
 
+/*
+ * Logging level to use if none is specified on the command line.
+ */
+#define DEFAULT_VERBOSITY      9
+
 
 /*
  * HOUSEKEEPING_WAKEUP is the number of seconds which pass between each pass
index 367cc792247466a3f3fc8f61feb0bc8fb94f8dc2..7eea262a32c7fd67f4dc59b1c69799b6466a2937 100644 (file)
@@ -67,7 +67,7 @@ pthread_mutex_t Critters[MAX_SEMAPHORES];     /* Things needing locking */
 pthread_key_t MyConKey;                                /* TSD key for MyContext() */
 
 int msock;                                     /* master listening socket */
-int verbosity = 9;                             /* Logging level */
+int verbosity = DEFAULT_VERBOSITY;             /* Logging level */
 
 struct CitContext masterCC;
 int rescan[2];                                 /* The Rescan Pipe */
@@ -175,17 +175,6 @@ void dump_tracked() {
        }
 #endif
 
-static pthread_t main_thread_id;
-
-#ifndef HAVE_PTHREAD_CANCEL
-/*
- * signal handler to fake thread cancellation; only required on BSDI as far
- * as I know.
- */
-static RETSIGTYPE cancel_thread(int signum) {
-       pthread_exit(NULL);
-       }
-#endif
 
 /*
  * we used to use master_cleanup() as a signal handler to shut down the server.
@@ -231,11 +220,13 @@ void init_sysdep(void) {
        signal(SIGQUIT, signal_cleanup);
        signal(SIGHUP, signal_cleanup);
        signal(SIGTERM, signal_cleanup);
+
+       /*
+        * Do not shut down the server on broken pipe signals, otherwise the
+        * whole Citadel service would come down whenever a single client
+        * socket breaks.
+        */
        signal(SIGPIPE, SIG_IGN);
-       main_thread_id = pthread_self();
-#ifndef HAVE_PTHREAD_CANCEL /* fake it - only BSDI afaik */
-       signal(SIGUSR1, cancel_thread);
-#endif
        }
 
 
@@ -305,7 +296,9 @@ int ig_tcp_server(int port_number, int queue_len)
 
 
 /*
- * Return a pointer to a thread's own CitContext structure (new)
+ * Return a pointer to the CitContext structure bound to the thread which
+ * called this function.  If there's no such binding (for example, if it's
+ * called by the housekeeper thread) then a generic 'master' CC is returned.
  */
 struct CitContext *MyContext(void) {
        struct CitContext *retCC;
@@ -316,7 +309,7 @@ struct CitContext *MyContext(void) {
 
 
 /*
- * Wedge our way into the context list.
+ * Initialize a new context and place it in the list.
  */
 struct CitContext *CreateNewContext(void) {
        struct CitContext *me;
@@ -341,55 +334,6 @@ struct CitContext *CreateNewContext(void) {
        return(me);
        }
 
-/*
- * Remove a context from the context list.
- */
-void RemoveContext(struct CitContext *con)
-{
-       struct CitContext *ptr = NULL;
-       struct CitContext *ToFree = NULL;
-
-       lprintf(7, "Starting RemoveContext()\n");
-       if (con==NULL) {
-               lprintf(5, "WARNING: RemoveContext() called with NULL!\n");
-               return;
-               }
-
-       /*
-        * session_count() starts its own S_SESSION_TABLE critical section;
-        * so do not call it from within this loop.
-        */
-       begin_critical_section(S_SESSION_TABLE);
-
-       if (ContextList == con) {
-               ToFree = ContextList;
-               ContextList = ContextList->next;
-               }
-       else {
-               for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
-                       if (ptr->next == con) {
-                               ToFree = ptr->next;
-                               ptr->next = ptr->next->next;
-                               }
-                       }
-               }
-
-
-       end_critical_section(S_SESSION_TABLE);
-
-       lprintf(7, "Closing socket %d\n", ToFree->client_socket);
-       close(ToFree->client_socket);
-
-        /* Tell the housekeeping thread to check to see if this is the time
-         * to initiate a scheduled shutdown event.
-         */
-        enter_housekeeping_cmd("SCHED_SHUTDOWN");
-
-       /* Free up the memory used by this context */
-       phree(ToFree);
-
-       lprintf(7, "Done with RemoveContext\n");
-       }
 
 
 /*
@@ -423,7 +367,7 @@ void client_write(char *buf, int nbytes)
                if (retval < 1) {
                        lprintf(2, "client_write() failed: %s\n",
                                strerror(errno));
-                       cleanup(errno);
+                       CC->state = CON_DYING;
                        }
                bytes_written = bytes_written + retval;
                }
@@ -479,7 +423,7 @@ int client_read_to(char *buf, int bytes, int timeout)
                if (rlen<1) {
                        lprintf(2, "client_read() failed: %s\n",
                                strerror(errno));
-                       cleanup(errno);
+                       CC->state = CON_DYING;
                        }
                len = len + rlen;
                }
@@ -541,6 +485,8 @@ void sysdep_master_cleanup(void) {
 
 /*
  * Terminate another session.
+ * FIX ... now we need some way to wake that session up so it knows it
+ * needs to terminate.
  */
 void kill_session(int session_to_kill) {
        struct CitContext *ptr;
@@ -672,7 +618,7 @@ int convert_login(char NameToConvert[]) {
  */
 int main(int argc, char **argv)
 {
-       THREAD HousekeepingThread;      /* Thread descriptor */
+       pthread_t HousekeepingThread;   /* Thread descriptor */
         pthread_attr_t attr;           /* Thread attributes */
        char tracefile[128];            /* Name of file to log traces to */
        int a, i;                       /* General-purpose variables */
@@ -743,6 +689,7 @@ int main(int argc, char **argv)
        /* Initialize... */
        init_sysdep();
        openlog("citserver",LOG_PID,LOG_USER);
+
        /* Load site-specific parameters */
        lprintf(7, "Loading citadel.config\n");
        get_config();
@@ -853,7 +800,7 @@ void worker_thread(void) {
        struct CitContext *con= NULL;   /* Temporary context pointer */
        struct sockaddr_in fsin;        /* Data for master socket */
        int alen;                       /* Data for master socket */
-       int ssock;                      /* Descriptor for master socket */
+       int ssock;                      /* Descriptor for client socket */
 
        while (!time_to_die) {
 
@@ -972,7 +919,7 @@ SETUP_FD:   FD_ZERO(&readfds);
                                do_command_loop();
                                pthread_setspecific(MyConKey, (void *)NULL);
                                if (bind_me->state == CON_DYING) {
-                                       RemoveContext(bind_me);
+                                       cleanup(bind_me);
                                } 
                                else {
                                        bind_me->state = CON_IDLE;
index ef5b9e700c1e5b5c370b46ae5eb18ffaf16d8cf0..e748522f430fb472e31ba38b5798eb144d20baf2 100644 (file)
@@ -7,7 +7,6 @@ int ig_tcp_server (int port_number, int queue_len);
 struct CitContext *MyContext (void);
 struct CitContext *CreateNewContext (void);
 void InitMyContext (struct CitContext *con);
-void RemoveContext (struct CitContext *con);
 int session_count (void);
 void client_write (char *buf, int nbytes);
 void cprintf (const char *format, ...);
index 608d4a584cb2dfa5f7771a2a66a20edca76fd585..5cf386354cdb7c410d70e23e92b7f7c4b1da78b9 100644 (file)
@@ -14,9 +14,6 @@
 #include <string.h>
 #include <syslog.h>
 #include <limits.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #ifndef ENABLE_CHKPWD
 #include "auth.h"
 #endif