* citserver.c: cleanup hook functions are now run under the proper context,
authorArt Cancro <ajc@citadel.org>
Mon, 17 Jan 2000 05:38:15 +0000 (05:38 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 17 Jan 2000 05:38:15 +0000 (05:38 +0000)
               even when initiated by the housekeeper thread
* serv_pop3.c: establish a place to hold the message list

citadel/ChangeLog
citadel/citserver.c
citadel/serv_pop3.c
citadel/serv_pop3.h [new file with mode: 0644]
citadel/sysdep.c
citadel/sysdep_decls.h

index 9876931dfbb8403e618b8548f67797bf76120fea..f6f3728c6f118c1dd0f9590282759060be5a54b2 100644 (file)
@@ -1,4 +1,9 @@
 $Log$
+Revision 1.445  2000/01/17 05:38:14  ajc
+* citserver.c: cleanup hook functions are now run under the proper context,
+               even when initiated by the housekeeper thread
+* serv_pop3.c: establish a place to hold the message list
+
 Revision 1.444  2000/01/17 04:26:39  ajc
 * Modified CtdlOutputMsg() to handle output to arbitrary sockets or files.
   This uses nested functions and may not be portable beyond GCC...
@@ -1558,3 +1563,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 14ab423b3a829f71ed61fbf2892e6d3b91a82d3e..b10167e5e3b918fa8eca3b9a2bd7ba22157d85e2 100644 (file)
@@ -158,6 +158,16 @@ void RemoveContext (struct CitContext *con)
                return;
        }
 
+       /* Run any cleanup routines registered by loadable modules.
+        * Note 1: This must occur *before* deallocate_user_data() because the
+        *         cleanup functions might touch dynamic session data.
+        * Note 2: We have to "become_session()" because the cleanup functions
+        *         might make references to "CC" assuming it's the right one.
+        */
+       become_session(con);
+       PerformSessionHooks(EVT_STOP);
+       become_session(NULL);
+
        /* Now handle all of the administrivia. */
        lprintf(7, "Calling logout(%d)\n", con->cs_pid);
        logout(con);
@@ -166,11 +176,6 @@ void RemoveContext (struct CitContext *con)
        unlink(con->temp);
        lprintf(3, "citserver[%3d]: ended.\n", con->cs_pid);
        
-       /* Run any cleanup routines registered by loadable modules.
-        * (Must occur *before* deallocate_user_data() because the cleanup
-        * functions might touch dynamic session data)
-        */
-       PerformSessionHooks(EVT_STOP);
 
        syslog(LOG_NOTICE,"session %d ended", con->cs_pid);
        
index 150993f240632b495a994a7498e80fbda9e5a57c..261f2ba3861055ae046aaa25879fa19aea20b593 100644 (file)
 #include "msgbase.h"
 #include "tools.h"
 #include "internet_addressing.h"
+#include "serv_pop3.h"
 
 
-struct pop3msg {
-       long msgnum;
-       size_t rfc822_length;
-       int deleted;
-       FILE *temp;
-};
-
-struct citpop3 {               /* Information about the current session */
-       struct pop3msg *msgs;
-       int num_msgs;
-};
-
-#define POP3 ((struct citpop3 *)CtdlGetUserData(SYM_POP3))
-
 long SYM_POP3;
 
 
 void pop3_cleanup_function(void) {
        int i;
 
+       /* Don't do this stuff if this is not a POP3 session! */
+       if (CC->h_command_function != pop3_command_loop) return;
+
        lprintf(9, "Performing POP3 cleanup hook\n");
 
        if (POP3->num_msgs > 0) for (i=0; i<POP3->num_msgs; ++i) {
                fclose(POP3->msgs[i].temp);
        }
        if (POP3->msgs != NULL) phree(POP3->msgs);
+
+       lprintf(9, "Finished POP3 cleanup hook\n");
 }
 
 
diff --git a/citadel/serv_pop3.h b/citadel/serv_pop3.h
new file mode 100644 (file)
index 0000000..13c7f18
--- /dev/null
@@ -0,0 +1,21 @@
+
+struct pop3msg {
+       long msgnum;
+       size_t rfc822_length;
+       int deleted;
+       FILE *temp;
+};
+
+struct citpop3 {               /* Information about the current session */
+       struct pop3msg *msgs;
+       int num_msgs;
+};
+
+#define POP3 ((struct citpop3 *)CtdlGetUserData(SYM_POP3))
+
+void pop3_cleanup_function(void);
+void pop3_greeting(void);
+void pop3_user(char *argbuf);
+void pop3_pass(char *argbuf);
+void pop3_list(char *argbuf);
+void pop3_command_loop(void);
index 0cd19053a53ab064009324bbe667c9e225ca615b..35a3d8f43797bd95671f9b60d92fa0a075efa258 100644 (file)
@@ -880,8 +880,12 @@ int main(int argc, char **argv)
 }
 
 
-
-
+/*
+ * Bind a thread to a context.
+ */
+inline void become_session(struct CitContext *which_con) {
+       pthread_setspecific(MyConKey, (void *)which_con );
+}
 
 
 
@@ -974,12 +978,10 @@ SETUP_FD: memcpy(&readfds, &masterfds, sizeof(fd_set) );
                                                SO_REUSEADDR,
                                                &i, sizeof(i));
 
-                                       pthread_setspecific(MyConKey,
-                                               (void *)con);
+                                       become_session(con);
                                        begin_session(con);
                                        serviceptr->h_greeting_function();
-                                       pthread_setspecific(MyConKey,
-                                               (void *)NULL);
+                                       become_session(NULL);
                                        con->state = CON_IDLE;
                                        goto SETUP_FD;
                                }
@@ -1021,9 +1023,9 @@ SETUP_FD: memcpy(&readfds, &masterfds, sizeof(fd_set) );
 
                        /* We're bound to a session, now do *one* command */
                        if (bind_me != NULL) {
-                               pthread_setspecific(MyConKey, (void *)bind_me);
+                               become_session(bind_me);
                                CC->h_command_function();
-                               pthread_setspecific(MyConKey, (void *)NULL);
+                               become_session(NULL);
                                bind_me->state = CON_IDLE;
                                if (bind_me->kill_me == 1) {
                                        RemoveContext(bind_me);
index 5c613966c3435ef0a35b2a8d118d91c0bc53e056..8fcbb82e81742dd248c74305f7ebdcdc38dfef14 100644 (file)
@@ -19,5 +19,6 @@ void start_daemon (int do_close_stdio);
 void cmd_nset (char *cmdbuf);
 int convert_login (char *NameToConvert);
 void worker_thread (void);
+inline void become_session(struct CitContext *which_con);
 
 extern int num_sessions;