From 8c6f5994ee07a408fef7c475fa516af3d016313f Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Mon, 17 Jan 2000 05:38:15 +0000 Subject: [PATCH] * 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 --- citadel/ChangeLog | 6 ++++++ citadel/citserver.c | 15 ++++++++++----- citadel/serv_pop3.c | 20 ++++++-------------- citadel/serv_pop3.h | 21 +++++++++++++++++++++ citadel/sysdep.c | 18 ++++++++++-------- citadel/sysdep_decls.h | 1 + 6 files changed, 54 insertions(+), 27 deletions(-) create mode 100644 citadel/serv_pop3.h diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 9876931df..f6f3728c6 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -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 Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/citserver.c b/citadel/citserver.c index 14ab423b3..b10167e5e 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -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); diff --git a/citadel/serv_pop3.c b/citadel/serv_pop3.c index 150993f24..261f2ba38 100644 --- a/citadel/serv_pop3.c +++ b/citadel/serv_pop3.c @@ -28,34 +28,26 @@ #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; inum_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 index 000000000..13c7f1872 --- /dev/null +++ b/citadel/serv_pop3.h @@ -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); diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 0cd19053a..35a3d8f43 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -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); diff --git a/citadel/sysdep_decls.h b/citadel/sysdep_decls.h index 5c613966c..8fcbb82e8 100644 --- a/citadel/sysdep_decls.h +++ b/citadel/sysdep_decls.h @@ -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; -- 2.39.2