2 * Citadel/UX "system dependent" stuff.
3 * See copyright.txt for copyright information.
7 * Here's where we (hopefully) have all the parts of the Citadel server that
8 * would need to be altered to run the server in a non-POSIX environment.
10 * Eventually we'll try porting to a different platform and either have
11 * multiple variants of this file or simply load it up with #ifdefs.
22 #include <sys/types.h>
24 #include <sys/socket.h>
27 #include <netinet/in.h>
43 #include "sysdep_decls.h"
44 #include "citserver.h"
48 #include "housekeeping.h"
49 #include "dynloader.h"
52 #ifdef HAVE_SYS_SELECT_H
53 #include <sys/select.h>
60 #ifdef DEBUG_MEMORY_LEAKS
61 struct TheHeap *heap = NULL;
64 pthread_mutex_t Critters[MAX_SEMAPHORES]; /* Things needing locking */
65 pthread_key_t MyConKey; /* TSD key for MyContext() */
67 int verbosity = DEFAULT_VERBOSITY; /* Logging level */
69 struct CitContext masterCC;
70 int rescan[2]; /* The Rescan Pipe */
71 time_t last_purge = 0; /* Last dead session purge */
72 int num_threads = 0; /* Current number of threads */
73 int num_sessions = 0; /* Current number of sessions */
75 fd_set masterfds; /* Master sockets etc. */
78 time_t last_timer = 0L; /* Last timer hook processing */
82 * lprintf() ... Write logging information
84 void lprintf(int loglevel, const char *format, ...) {
88 va_start(arg_ptr, format);
89 vsprintf(buf, format, arg_ptr);
92 if (loglevel <= verbosity) {
93 fprintf(stderr, "%s", buf);
97 PerformLogHooks(loglevel, buf);
102 #ifdef DEBUG_MEMORY_LEAKS
103 void *tracked_malloc(size_t tsize, char *tfile, int tline) {
105 struct TheHeap *hptr;
109 lprintf(3, "DANGER! mallok(%d) at %s:%d failed!\n",
110 tsize, tfile, tline);
114 hptr = (struct TheHeap *) malloc(sizeof(struct TheHeap));
115 strcpy(hptr->h_file, tfile);
116 hptr->h_line = tline;
123 char *tracked_strdup(const char *orig, char *tfile, int tline) {
126 s = tracked_malloc( (strlen(orig)+1), tfile, tline);
127 if (s == NULL) return NULL;
133 void tracked_free(void *ptr) {
134 struct TheHeap *hptr, *freeme;
136 if (heap->h_ptr == ptr) {
142 for (hptr=heap; hptr->next!=NULL; hptr=hptr->next) {
143 if (hptr->next->h_ptr == ptr) {
145 hptr->next = hptr->next->next;
154 void *tracked_realloc(void *ptr, size_t size) {
156 struct TheHeap *hptr;
158 newptr = realloc(ptr, size);
160 for (hptr=heap; hptr!=NULL; hptr=hptr->next) {
161 if (hptr->h_ptr == ptr) hptr->h_ptr = newptr;
168 void dump_tracked() {
169 struct TheHeap *hptr;
171 cprintf("%d Here's what's allocated...\n", LISTING_FOLLOWS);
172 for (hptr=heap; hptr!=NULL; hptr=hptr->next) {
173 cprintf("%20s %5d\n",
174 hptr->h_file, hptr->h_line);
186 * we used to use master_cleanup() as a signal handler to shut down the server.
187 * however, master_cleanup() and the functions it calls do some things that
188 * aren't such a good idea to do from a signal handler: acquiring mutexes,
189 * playing with signal masks on BSDI systems, etc. so instead we install the
190 * following signal handler to set a global variable to inform the main loop
191 * that it's time to call master_cleanup() and exit.
194 static volatile int time_to_die = 0;
196 static RETSIGTYPE signal_cleanup(int signum) {
202 * Some initialization stuff...
204 void init_sysdep(void) {
207 /* Set up a bunch of semaphores to be used for critical sections */
208 for (a=0; a<MAX_SEMAPHORES; ++a) {
209 pthread_mutex_init(&Critters[a], NULL);
213 * Set up a place to put thread-specific data.
214 * We only need a single pointer per thread - it points to the
215 * thread's CitContext structure in the ContextList linked list.
217 if (pthread_key_create(&MyConKey, NULL) != 0) {
218 lprintf(1, "Can't create TSD key!! %s\n", strerror(errno));
222 * The action for unexpected signals and exceptions should be to
223 * call signal_cleanup() to gracefully shut down the server.
225 signal(SIGINT, signal_cleanup);
226 signal(SIGQUIT, signal_cleanup);
227 signal(SIGHUP, signal_cleanup);
228 signal(SIGTERM, signal_cleanup);
231 * Do not shut down the server on broken pipe signals, otherwise the
232 * whole Citadel service would come down whenever a single client
235 signal(SIGPIPE, SIG_IGN);
240 * Obtain a semaphore lock to begin a critical section.
242 void begin_critical_section(int which_one)
244 /* lprintf(9, "begin_critical_section(%d)\n", which_one); */
245 pthread_mutex_lock(&Critters[which_one]);
249 * Release a semaphore lock to end a critical section.
251 void end_critical_section(int which_one)
253 /* lprintf(9, "end_critical_section(%d)\n", which_one); */
254 pthread_mutex_unlock(&Critters[which_one]);
260 * This is a generic function to set up a master socket for listening on
261 * a TCP port. The server shuts down if the bind fails.
263 int ig_tcp_server(int port_number, int queue_len)
265 struct sockaddr_in sin;
268 memset(&sin, 0, sizeof(sin));
269 sin.sin_family = AF_INET;
270 sin.sin_addr.s_addr = INADDR_ANY;
272 if (port_number == 0) {
273 lprintf(1, "citserver: illegal port number specified\n");
277 sin.sin_port = htons((u_short)port_number);
279 s = socket(PF_INET, SOCK_STREAM, (getprotobyname("tcp")->p_proto));
281 lprintf(1, "citserver: Can't create a socket: %s\n",
286 /* Set the SO_REUSEADDR socket option, because it makes sense. */
288 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
290 if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
291 lprintf(1, "citserver: Can't bind: %s\n", strerror(errno));
295 if (listen(s, queue_len) < 0) {
296 lprintf(1, "citserver: Can't listen: %s\n", strerror(errno));
306 * Return a pointer to the CitContext structure bound to the thread which
307 * called this function. If there's no such binding (for example, if it's
308 * called by the housekeeper thread) then a generic 'master' CC is returned.
310 struct CitContext *MyContext(void) {
311 struct CitContext *retCC;
312 retCC = (struct CitContext *) pthread_getspecific(MyConKey);
313 if (retCC == NULL) retCC = &masterCC;
319 * Initialize a new context and place it in the list.
321 struct CitContext *CreateNewContext(void) {
322 struct CitContext *me, *ptr;
326 me = (struct CitContext *) mallok(sizeof(struct CitContext));
328 lprintf(1, "citserver: can't allocate memory!!\n");
331 memset(me, 0, sizeof(struct CitContext));
333 /* The new context will be created already in the CON_EXECUTING state
334 * in order to prevent another thread from grabbing it while it's
337 me->state = CON_EXECUTING;
339 begin_critical_section(S_SESSION_TABLE);
341 /* obtain a unique session number */
344 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
345 if (ptr->cs_pid == num) {
350 } while (startover == 1);
353 me->next = ContextList;
357 end_critical_section(S_SESSION_TABLE);
364 * client_write() ... Send binary data to the client.
366 void client_write(char *buf, int nbytes)
368 int bytes_written = 0;
372 if (CC->redirect_fp != NULL) {
373 fwrite(buf, nbytes, 1, CC->redirect_fp);
377 if (CC->redirect_sock > 0) {
378 sock = CC->redirect_sock; /* and continue below... */
381 sock = CC->client_socket;
384 while (bytes_written < nbytes) {
385 retval = write(sock, &buf[bytes_written],
386 nbytes - bytes_written);
388 lprintf(2, "client_write() failed: %s\n",
390 if (sock == CC->client_socket) CC->kill_me = 1;
393 bytes_written = bytes_written + retval;
399 * cprintf() ... Send formatted printable data to the client. It is
400 * implemented in terms of client_write() but remains in
401 * sysdep.c in case we port to somewhere without va_args...
403 void cprintf(const char *format, ...) {
407 va_start(arg_ptr, format);
408 if (vsnprintf(buf, sizeof buf, format, arg_ptr) == -1)
409 buf[sizeof buf - 2] = '\n';
410 client_write(buf, strlen(buf));
416 * Read data from the client socket.
418 * 1 Requested number of bytes has been read.
419 * 0 Request timed out.
420 * -1 The socket is broken.
421 * If the socket breaks, the session will be terminated.
423 int client_read_to(char *buf, int bytes, int timeout)
433 FD_SET(CC->client_socket, &rfds);
437 retval = select( (CC->client_socket)+1,
438 &rfds, NULL, NULL, &tv);
440 if (FD_ISSET(CC->client_socket, &rfds) == 0) {
444 rlen = read(CC->client_socket, &buf[len], bytes-len);
446 lprintf(2, "client_read() failed: %s\n",
457 * Read data from the client socket with default timeout.
458 * (This is implemented in terms of client_read_to() and could be
459 * justifiably moved out of sysdep.c)
461 int client_read(char *buf, int bytes)
463 return(client_read_to(buf, bytes, config.c_sleeping));
468 * client_gets() ... Get a LF-terminated line of text from the client.
469 * (This is implemented in terms of client_read() and could be
470 * justifiably moved out of sysdep.c)
472 int client_gets(char *buf)
476 /* Read one character at a time.
479 retval = client_read(&buf[i], 1);
480 if (retval != 1 || buf[i] == '\n' || i == 255)
484 /* If we got a long line, discard characters until the newline.
487 while (buf[i] != '\n' && retval == 1)
488 retval = client_read(&buf[i], 1);
490 /* Strip the trailing newline and any trailing nonprintables (cr's)
493 while ((strlen(buf)>0)&&(!isprint(buf[strlen(buf)-1])))
494 buf[strlen(buf)-1] = 0;
501 * The system-dependent part of master_cleanup() - close the master socket.
503 void sysdep_master_cleanup(void) {
504 struct ServiceFunctionHook *serviceptr;
507 * close all protocol master sockets
509 for (serviceptr = ServiceHookTable; serviceptr != NULL;
510 serviceptr = serviceptr->next ) {
511 lprintf(3, "Closing listener on port %d\n",
512 serviceptr->tcp_port);
513 close(serviceptr->msock);
519 * Terminate another session.
520 * (This could justifiably be moved out of sysdep.c because it
521 * no longer does anything that is system-dependent.)
523 void kill_session(int session_to_kill) {
524 struct CitContext *ptr;
526 begin_critical_section(S_SESSION_TABLE);
527 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
528 if (ptr->cs_pid == session_to_kill) {
532 end_critical_section(S_SESSION_TABLE);
539 * Start running as a daemon. Only close stdio if do_close_stdio is set.
541 void start_daemon(int do_close_stdio) {
542 if (do_close_stdio) {
547 signal(SIGHUP,SIG_IGN);
548 signal(SIGINT,SIG_IGN);
549 signal(SIGQUIT,SIG_IGN);
550 if (fork()!=0) exit(0);
556 * Tie in to the 'netsetup' program.
558 * (We're going to hope that netsetup never feeds more than 4096 bytes back.)
560 void cmd_nset(char *cmdbuf)
567 char netsetup_args[3][256];
569 if (CC->usersupp.axlevel < 6) {
570 cprintf("%d Higher access required.\n",
571 ERROR + HIGHER_ACCESS_REQUIRED);
575 for (a=1; a<=3; ++a) {
576 if (num_parms(cmdbuf) >= a) {
577 extract(netsetup_args[a-1], cmdbuf, a-1);
578 for (b=0; b<strlen(netsetup_args[a-1]); ++b) {
579 if (netsetup_args[a-1][b] == 34) {
580 netsetup_args[a-1][b] = '_';
585 netsetup_args[a-1][0] = 0;
589 sprintf(fbuf, "./netsetup \"%s\" \"%s\" \"%s\" </dev/null 2>&1",
590 netsetup_args[0], netsetup_args[1], netsetup_args[2]);
591 netsetup = popen(fbuf, "r");
592 if (netsetup == NULL) {
593 cprintf("%d %s\n", ERROR, strerror(errno));
598 while (ch = getc(netsetup), (ch > 0)) {
599 fbuf[strlen(fbuf)+1] = 0;
600 fbuf[strlen(fbuf)] = ch;
603 retcode = pclose(netsetup);
606 for (a=0; a<strlen(fbuf); ++a) {
607 if (fbuf[a] < 32) fbuf[a] = 32;
610 cprintf("%d %s\n", ERROR, fbuf);
614 cprintf("%d Command succeeded. Output follows:\n", LISTING_FOLLOWS);
616 if (fbuf[strlen(fbuf)-1] != 10) cprintf("\n");
623 * Generic routine to convert a login name to a full name (gecos)
624 * Returns nonzero if a conversion took place
626 int convert_login(char NameToConvert[]) {
630 pw = getpwnam(NameToConvert);
635 strcpy(NameToConvert, pw->pw_gecos);
636 for (a=0; a<strlen(NameToConvert); ++a) {
637 if (NameToConvert[a] == ',') NameToConvert[a] = 0;
646 * Purge all sessions which have the 'kill_me' flag set.
647 * This function has code to prevent it from running more than once every
648 * few seconds, because running it after every single unbind would waste a lot
649 * of CPU time and keep the context list locked too much.
651 * After that's done, we raise or lower the size of the worker thread pool
652 * if such an action is appropriate.
654 void dead_session_purge(void) {
655 struct CitContext *ptr, *rem;
659 if ( (time(NULL) - last_purge) < 5 ) return; /* Too soon, go away */
664 begin_critical_section(S_SESSION_TABLE);
665 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
666 if ( (ptr->state == CON_IDLE) && (ptr->kill_me) ) {
670 end_critical_section(S_SESSION_TABLE);
672 /* RemoveContext() enters its own S_SESSION_TABLE critical
673 * section, so we have to do it like this.
676 lprintf(9, "Purging session %d\n", rem->cs_pid);
680 } while (rem != NULL);
683 /* Raise or lower the size of the worker thread pool if such
684 * an action is appropriate.
687 if ( (num_sessions > num_threads)
688 && (num_threads < config.c_max_workers) ) {
690 pthread_attr_init(&attr);
691 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
692 if (pthread_create(&newthread, &attr,
693 (void* (*)(void*)) worker_thread, NULL) != 0) {
694 lprintf(1, "Can't create worker thead: %s\n",
700 else if ( (num_sessions < num_threads)
701 && (num_threads > config.c_min_workers) ) {
713 * Redirect a session's output to a file or socket.
714 * This function may be called with a file handle *or* a socket (but not
715 * both). Call with neither to return output to its normal client socket.
717 void CtdlRedirectOutput(FILE *fp, int sock) {
719 if (fp != NULL) CC->redirect_fp = fp;
720 else CC->redirect_fp = NULL;
722 if (sock > 0) CC->redirect_sock = sock;
723 else CC->redirect_sock = (-1);
729 * masterCC is the context we use when not attached to a session. This
730 * function initializes it.
732 void InitializeMasterCC(void) {
733 memset(&masterCC, 0, sizeof(struct CitContext));
734 masterCC.internal_pgm = 1;
740 * Here's where it all begins.
742 int main(int argc, char **argv)
744 pthread_t HousekeepingThread; /* Thread descriptor */
745 pthread_attr_t attr; /* Thread attributes */
746 char tracefile[128]; /* Name of file to log traces to */
747 int a, i; /* General-purpose variables */
749 int drop_root_perms = 1;
751 struct ServiceFunctionHook *serviceptr;
753 /* specify default port name and trace file */
754 strcpy(tracefile, "");
756 /* initialize the master context */
757 InitializeMasterCC();
759 /* parse command-line arguments */
760 for (a=1; a<argc; ++a) {
762 /* -t specifies where to log trace messages to */
763 if (!strncmp(argv[a], "-t", 2)) {
764 strcpy(tracefile, argv[a]);
765 strcpy(tracefile, &tracefile[2]);
766 freopen(tracefile, "r", stdin);
767 freopen(tracefile, "w", stdout);
768 freopen(tracefile, "w", stderr);
771 /* run in the background if -d was specified */
772 else if (!strcmp(argv[a], "-d")) {
773 start_daemon( (strlen(tracefile) > 0) ? 0 : 1 ) ;
776 /* -x specifies the desired logging level */
777 else if (!strncmp(argv[a], "-x", 2)) {
778 verbosity = atoi(&argv[a][2]);
781 else if (!strncmp(argv[a], "-h", 2)) {
782 safestrncpy(bbs_home_directory, &argv[a][2],
783 sizeof bbs_home_directory);
787 else if (!strncmp(argv[a], "-f", 2)) {
791 /* -r tells the server not to drop root permissions. don't use
792 * this unless you know what you're doing. this should be
793 * removed in the next release if it proves unnecessary. */
794 else if (!strcmp(argv[a], "-r"))
797 /* any other parameter makes it crash and burn */
799 lprintf(1, "citserver: usage: "
800 "citserver [-tTraceFile] [-d] [-f]"
801 " [-xLogLevel] [-hHomeDir]\n");
807 /* Tell 'em who's in da house */
809 "\nMultithreaded message server for Citadel/UX\n"
810 "Copyright (C) 1987-1999 by the Citadel/UX development team.\n"
811 "Citadel/UX is free software, covered by the GNU General Public License, and\n"
812 "you are welcome to change it and/or distribute copies of it under certain\n"
813 "conditions. There is absolutely no warranty for this software. Please\n"
814 "read the 'COPYING.txt' file for details.\n\n");
818 openlog("citserver",LOG_PID,LOG_USER);
820 /* Load site-specific parameters */
821 lprintf(7, "Loading citadel.config\n");
825 * Do non system dependent startup functions.
830 * Bind the server to our favorite ports.
832 CtdlRegisterServiceHook(config.c_port_number,
833 citproto_begin_session,
837 * Load any server-side modules (plugins) available here.
839 lprintf(7, "Initializing loadable modules\n");
840 if ((moddir = malloc(strlen(bbs_home_directory) + 9)) != NULL) {
841 sprintf(moddir, "%s/modules", bbs_home_directory);
842 DLoader_Init(moddir);
847 * The rescan pipe exists so that worker threads can be woken up and
848 * told to re-scan the context list for fd's to listen on. This is
849 * necessary, for example, when a context is about to go idle and needs
850 * to get back on that list.
853 lprintf(1, "Can't create rescan pipe!\n");
858 * Set up a fd_set containing all the master sockets to which we
859 * always listen. It's computationally less expensive to just copy
860 * this to a local fd_set when starting a new select() and then add
861 * the client sockets than it is to initialize a new one and then
862 * figure out what to put there.
866 FD_SET(rescan[0], &masterfds);
867 if (rescan[0] > masterhighest) masterhighest = rescan[0];
869 for (serviceptr = ServiceHookTable; serviceptr != NULL;
870 serviceptr = serviceptr->next ) {
871 FD_SET(serviceptr->msock, &masterfds);
872 if (serviceptr->msock > masterhighest) {
873 masterhighest = serviceptr->msock;
879 * Now that we've bound the sockets, change to the BBS user id and its
880 * corresponding group ids
882 if (drop_root_perms) {
883 if ((pw = getpwuid(BBSUID)) == NULL)
884 lprintf(1, "WARNING: getpwuid(%d): %s\n"
885 "Group IDs will be incorrect.\n", BBSUID,
888 initgroups(pw->pw_name, pw->pw_gid);
889 if (setgid(pw->pw_gid))
890 lprintf(3, "setgid(%d): %s\n", pw->pw_gid,
893 lprintf(7, "Changing uid to %d\n", BBSUID);
894 if (setuid(BBSUID) != 0) {
895 lprintf(3, "setuid() failed: %s\n", strerror(errno));
900 * Create the housekeeper thread
902 lprintf(7, "Starting housekeeper thread\n");
903 pthread_attr_init(&attr);
904 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
905 if (pthread_create(&HousekeepingThread, &attr,
906 (void* (*)(void*)) housekeeping_loop, NULL) != 0) {
907 lprintf(1, "Can't create housekeeping thead: %s\n",
913 * Now create a bunch of worker threads.
915 for (i=0; i<(config.c_min_workers-1); ++i) {
916 pthread_attr_init(&attr);
917 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
918 if (pthread_create(&HousekeepingThread, &attr,
919 (void* (*)(void*)) worker_thread, NULL) != 0) {
920 lprintf(1, "Can't create worker thead: %s\n",
925 /* Now this thread can become a worker as well. */
933 * Bind a thread to a context.
935 inline void become_session(struct CitContext *which_con) {
936 pthread_setspecific(MyConKey, (void *)which_con );
942 * This loop just keeps going and going and going...
944 void worker_thread(void) {
948 struct CitContext *ptr;
949 struct CitContext *bind_me = NULL;
952 struct CitContext *con= NULL; /* Temporary context pointer */
953 struct ServiceFunctionHook *serviceptr;
954 struct sockaddr_in fsin; /* Data for master socket */
955 int alen; /* Data for master socket */
956 int ssock; /* Descriptor for client socket */
961 while (!time_to_die) {
964 * A naive implementation would have all idle threads
965 * calling select() and then they'd all wake up at once. We
966 * solve this problem by putting the select() in a critical
967 * section, so only one thread has the opportunity to wake
968 * up. If we wake up on the master socket, create a new
969 * session context; otherwise, just bind the thread to the
970 * context we want and go on our merry way.
973 begin_critical_section(S_I_WANNA_SELECT);
974 SETUP_FD: memcpy(&readfds, &masterfds, sizeof(fd_set) );
975 highest = masterhighest;
976 begin_critical_section(S_SESSION_TABLE);
977 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
978 if (ptr->state == CON_IDLE) {
979 FD_SET(ptr->client_socket, &readfds);
980 if (ptr->client_socket > highest)
981 highest = ptr->client_socket;
984 end_critical_section(S_SESSION_TABLE);
986 tv.tv_sec = 60; /* wake up every minute if no input */
988 retval = select(highest + 1, &readfds, NULL, NULL, &tv);
990 /* Now figure out who made this select() unblock.
991 * First, check for an error or exit condition.
994 end_critical_section(S_I_WANNA_SELECT);
995 lprintf(9, "Exiting (%s)\n", strerror(errno));
999 /* Next, check to see if it's a new client connecting
1000 * on the master socket.
1002 else for (serviceptr = ServiceHookTable; serviceptr != NULL;
1003 serviceptr = serviceptr->next ) {
1005 if (FD_ISSET(serviceptr->msock, &readfds)) {
1007 ssock = accept(serviceptr->msock,
1008 (struct sockaddr *)&fsin, &alen);
1010 lprintf(2, "citserver: accept(): %s\n",
1014 lprintf(7, "citserver: "
1015 "New client socket %d\n",
1018 /* New context will be created already
1019 * set up in the CON_EXECUTING state.
1021 con = CreateNewContext();
1023 /* Assign new socket number to it. */
1024 con->client_socket = ssock;
1025 con->h_command_function =
1026 serviceptr->h_command_function;
1028 /* Set the SO_REUSEADDR socket option */
1030 setsockopt(ssock, SOL_SOCKET,
1034 become_session(con);
1036 serviceptr->h_greeting_function();
1037 become_session(NULL);
1038 con->state = CON_IDLE;
1044 /* If the rescan pipe went active, someone is telling this
1045 * thread that the &readfds needs to be refreshed with more
1048 if (!time_to_die) if (FD_ISSET(rescan[0], &readfds)) {
1049 read(rescan[0], &junk, 1);
1053 /* It must be a client socket. Find a context that has data
1054 * waiting on its socket *and* is in the CON_IDLE state.
1058 begin_critical_section(S_SESSION_TABLE);
1059 for (ptr = ContextList;
1060 ( (ptr != NULL) && (bind_me == NULL) );
1062 if ( (FD_ISSET(ptr->client_socket, &readfds))
1063 && (ptr->state == CON_IDLE) ) {
1067 if (bind_me != NULL) {
1068 /* Found one. Stake a claim to it before
1069 * letting anyone else touch the context list.
1071 bind_me->state = CON_EXECUTING;
1074 end_critical_section(S_SESSION_TABLE);
1075 end_critical_section(S_I_WANNA_SELECT);
1077 /* We're bound to a session, now do *one* command */
1078 if (bind_me != NULL) {
1079 become_session(bind_me);
1080 CC->h_command_function();
1081 become_session(NULL);
1082 bind_me->state = CON_IDLE;
1083 if (bind_me->kill_me == 1) {
1084 RemoveContext(bind_me);
1086 write(rescan[1], &junk, 1);
1090 dead_session_purge();
1091 if ((time(NULL) - last_timer) > 60L) {
1092 last_timer = time(NULL);
1093 PerformSessionHooks(EVT_TIMER);
1097 /* If control reaches this point, the server is shutting down */