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 pthread_mutex_lock(&Critters[which_one]);
248 * Release a semaphore lock to end a critical section.
250 void end_critical_section(int which_one)
252 pthread_mutex_unlock(&Critters[which_one]);
258 * This is a generic function to set up a master socket for listening on
259 * a TCP port. The server shuts down if the bind fails.
261 int ig_tcp_server(int port_number, int queue_len)
263 struct sockaddr_in sin;
266 memset(&sin, 0, sizeof(sin));
267 sin.sin_family = AF_INET;
268 sin.sin_addr.s_addr = INADDR_ANY;
270 if (port_number == 0) {
271 lprintf(1, "citserver: illegal port number specified\n");
275 sin.sin_port = htons((u_short)port_number);
277 s = socket(PF_INET, SOCK_STREAM, (getprotobyname("tcp")->p_proto));
279 lprintf(1, "citserver: Can't create a socket: %s\n",
284 /* Set the SO_REUSEADDR socket option, because it makes sense. */
286 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
288 if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
289 lprintf(1, "citserver: Can't bind: %s\n", strerror(errno));
293 if (listen(s, queue_len) < 0) {
294 lprintf(1, "citserver: Can't listen: %s\n", strerror(errno));
304 * Return a pointer to the CitContext structure bound to the thread which
305 * called this function. If there's no such binding (for example, if it's
306 * called by the housekeeper thread) then a generic 'master' CC is returned.
308 struct CitContext *MyContext(void) {
309 struct CitContext *retCC;
310 retCC = (struct CitContext *) pthread_getspecific(MyConKey);
311 if (retCC == NULL) retCC = &masterCC;
317 * Initialize a new context and place it in the list.
319 struct CitContext *CreateNewContext(void) {
320 struct CitContext *me, *ptr;
324 me = (struct CitContext *) mallok(sizeof(struct CitContext));
326 lprintf(1, "citserver: can't allocate memory!!\n");
329 memset(me, 0, sizeof(struct CitContext));
331 /* The new context will be created already in the CON_EXECUTING state
332 * in order to prevent another thread from grabbing it while it's
335 me->state = CON_EXECUTING;
337 begin_critical_section(S_SESSION_TABLE);
339 /* obtain a unique session number */
342 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
343 if (ptr->cs_pid == num) {
348 } while (startover == 1);
351 me->next = ContextList;
355 end_critical_section(S_SESSION_TABLE);
362 * client_write() ... Send binary data to the client.
364 void client_write(char *buf, int nbytes)
366 int bytes_written = 0;
370 if (CC->redirect_fp != NULL) {
371 fwrite(buf, nbytes, 1, CC->redirect_fp);
375 if (CC->redirect_sock > 0) {
376 sock = CC->redirect_sock; /* and continue below... */
379 sock = CC->client_socket;
382 while (bytes_written < nbytes) {
383 retval = write(sock, &buf[bytes_written],
384 nbytes - bytes_written);
386 lprintf(2, "client_write() failed: %s\n",
388 if (sock == CC->client_socket) CC->kill_me = 1;
391 bytes_written = bytes_written + retval;
397 * cprintf() ... Send formatted printable data to the client. It is
398 * implemented in terms of client_write() but remains in
399 * sysdep.c in case we port to somewhere without va_args...
401 void cprintf(const char *format, ...) {
405 va_start(arg_ptr, format);
406 if (vsnprintf(buf, sizeof buf, format, arg_ptr) == -1)
407 buf[sizeof buf - 2] = '\n';
408 client_write(buf, strlen(buf));
414 * Read data from the client socket.
416 * 1 Requested number of bytes has been read.
417 * 0 Request timed out.
418 * -1 The socket is broken.
419 * If the socket breaks, the session will be terminated.
421 int client_read_to(char *buf, int bytes, int timeout)
431 FD_SET(CC->client_socket, &rfds);
435 retval = select( (CC->client_socket)+1,
436 &rfds, NULL, NULL, &tv);
438 if (FD_ISSET(CC->client_socket, &rfds) == 0) {
442 rlen = read(CC->client_socket, &buf[len], bytes-len);
444 lprintf(2, "client_read() failed: %s\n",
455 * Read data from the client socket with default timeout.
456 * (This is implemented in terms of client_read_to() and could be
457 * justifiably moved out of sysdep.c)
459 int client_read(char *buf, int bytes)
461 return(client_read_to(buf, bytes, config.c_sleeping));
466 * client_gets() ... Get a LF-terminated line of text from the client.
467 * (This is implemented in terms of client_read() and could be
468 * justifiably moved out of sysdep.c)
470 int client_gets(char *buf)
474 /* Read one character at a time.
477 retval = client_read(&buf[i], 1);
478 if (retval != 1 || buf[i] == '\n' || i == 255)
482 /* If we got a long line, discard characters until the newline.
485 while (buf[i] != '\n' && retval == 1)
486 retval = client_read(&buf[i], 1);
488 /* Strip the trailing newline and any trailing nonprintables (cr's)
491 while ((strlen(buf)>0)&&(!isprint(buf[strlen(buf)-1])))
492 buf[strlen(buf)-1] = 0;
499 * The system-dependent part of master_cleanup() - close the master socket.
501 void sysdep_master_cleanup(void) {
502 /* FIXME close all protocol master sockets here */
507 * Terminate another session.
508 * (This could justifiably be moved out of sysdep.c because it
509 * no longer does anything that is system-dependent.)
511 void kill_session(int session_to_kill) {
512 struct CitContext *ptr;
514 begin_critical_section(S_SESSION_TABLE);
515 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
516 if (ptr->cs_pid == session_to_kill) {
520 end_critical_section(S_SESSION_TABLE);
527 * Start running as a daemon. Only close stdio if do_close_stdio is set.
529 void start_daemon(int do_close_stdio) {
530 if (do_close_stdio) {
535 signal(SIGHUP,SIG_IGN);
536 signal(SIGINT,SIG_IGN);
537 signal(SIGQUIT,SIG_IGN);
538 if (fork()!=0) exit(0);
544 * Tie in to the 'netsetup' program.
546 * (We're going to hope that netsetup never feeds more than 4096 bytes back.)
548 void cmd_nset(char *cmdbuf)
555 char netsetup_args[3][256];
557 if (CC->usersupp.axlevel < 6) {
558 cprintf("%d Higher access required.\n",
559 ERROR + HIGHER_ACCESS_REQUIRED);
563 for (a=1; a<=3; ++a) {
564 if (num_parms(cmdbuf) >= a) {
565 extract(netsetup_args[a-1], cmdbuf, a-1);
566 for (b=0; b<strlen(netsetup_args[a-1]); ++b) {
567 if (netsetup_args[a-1][b] == 34) {
568 netsetup_args[a-1][b] = '_';
573 netsetup_args[a-1][0] = 0;
577 sprintf(fbuf, "./netsetup \"%s\" \"%s\" \"%s\" </dev/null 2>&1",
578 netsetup_args[0], netsetup_args[1], netsetup_args[2]);
579 netsetup = popen(fbuf, "r");
580 if (netsetup == NULL) {
581 cprintf("%d %s\n", ERROR, strerror(errno));
586 while (ch = getc(netsetup), (ch > 0)) {
587 fbuf[strlen(fbuf)+1] = 0;
588 fbuf[strlen(fbuf)] = ch;
591 retcode = pclose(netsetup);
594 for (a=0; a<strlen(fbuf); ++a) {
595 if (fbuf[a] < 32) fbuf[a] = 32;
598 cprintf("%d %s\n", ERROR, fbuf);
602 cprintf("%d Command succeeded. Output follows:\n", LISTING_FOLLOWS);
604 if (fbuf[strlen(fbuf)-1] != 10) cprintf("\n");
611 * Generic routine to convert a login name to a full name (gecos)
612 * Returns nonzero if a conversion took place
614 int convert_login(char NameToConvert[]) {
618 pw = getpwnam(NameToConvert);
623 strcpy(NameToConvert, pw->pw_gecos);
624 for (a=0; a<strlen(NameToConvert); ++a) {
625 if (NameToConvert[a] == ',') NameToConvert[a] = 0;
634 * Purge all sessions which have the 'kill_me' flag set.
635 * This function has code to prevent it from running more than once every
636 * few seconds, because running it after every single unbind would waste a lot
637 * of CPU time and keep the context list locked too much.
639 * After that's done, we raise or lower the size of the worker thread pool
640 * if such an action is appropriate.
642 void dead_session_purge(void) {
643 struct CitContext *ptr, *rem;
647 if ( (time(NULL) - last_purge) < 5 ) return; /* Too soon, go away */
652 begin_critical_section(S_SESSION_TABLE);
653 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
654 if ( (ptr->state == CON_IDLE) && (ptr->kill_me) ) {
658 end_critical_section(S_SESSION_TABLE);
660 /* RemoveContext() enters its own S_SESSION_TABLE critical
661 * section, so we have to do it like this.
664 lprintf(9, "Purging session %d\n", rem->cs_pid);
668 } while (rem != NULL);
671 /* Raise or lower the size of the worker thread pool if such
672 * an action is appropriate.
675 if ( (num_sessions > num_threads)
676 && (num_threads < config.c_max_workers) ) {
678 pthread_attr_init(&attr);
679 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
680 if (pthread_create(&newthread, &attr,
681 (void* (*)(void*)) worker_thread, NULL) != 0) {
682 lprintf(1, "Can't create worker thead: %s\n",
688 else if ( (num_sessions < num_threads)
689 && (num_threads > config.c_min_workers) ) {
701 * Redirect a session's output to a file or socket.
702 * This function may be called with a file handle *or* a socket (but not
703 * both). Call with neither to return output to its normal client socket.
705 void CtdlRedirectOutput(FILE *fp, int sock) {
707 if (fp != NULL) CC->redirect_fp = fp;
708 else CC->redirect_fp = NULL;
710 if (sock > 0) CC->redirect_sock = sock;
711 else CC->redirect_sock = (-1);
717 * masterCC is the context we use when not attached to a session. This
718 * function initializes it.
720 void InitializeMasterCC(void) {
721 memset(&masterCC, 0, sizeof(struct CitContext));
722 masterCC.internal_pgm = 1;
728 * Here's where it all begins.
730 int main(int argc, char **argv)
732 pthread_t HousekeepingThread; /* Thread descriptor */
733 pthread_attr_t attr; /* Thread attributes */
734 char tracefile[128]; /* Name of file to log traces to */
735 int a, i; /* General-purpose variables */
737 int drop_root_perms = 1;
739 struct ServiceFunctionHook *serviceptr;
741 /* specify default port name and trace file */
742 strcpy(tracefile, "");
744 /* initialize the master context */
745 InitializeMasterCC();
747 /* parse command-line arguments */
748 for (a=1; a<argc; ++a) {
750 /* -t specifies where to log trace messages to */
751 if (!strncmp(argv[a], "-t", 2)) {
752 strcpy(tracefile, argv[a]);
753 strcpy(tracefile, &tracefile[2]);
754 freopen(tracefile, "r", stdin);
755 freopen(tracefile, "w", stdout);
756 freopen(tracefile, "w", stderr);
759 /* run in the background if -d was specified */
760 else if (!strcmp(argv[a], "-d")) {
761 start_daemon( (strlen(tracefile) > 0) ? 0 : 1 ) ;
764 /* -x specifies the desired logging level */
765 else if (!strncmp(argv[a], "-x", 2)) {
766 verbosity = atoi(&argv[a][2]);
769 else if (!strncmp(argv[a], "-h", 2)) {
770 safestrncpy(bbs_home_directory, &argv[a][2],
771 sizeof bbs_home_directory);
775 else if (!strncmp(argv[a], "-f", 2)) {
779 /* -r tells the server not to drop root permissions. don't use
780 * this unless you know what you're doing. this should be
781 * removed in the next release if it proves unnecessary. */
782 else if (!strcmp(argv[a], "-r"))
785 /* any other parameter makes it crash and burn */
787 lprintf(1, "citserver: usage: "
788 "citserver [-tTraceFile] [-d] [-f]"
789 " [-xLogLevel] [-hHomeDir]\n");
795 /* Tell 'em who's in da house */
797 "\nMultithreaded message server for Citadel/UX\n"
798 "Copyright (C) 1987-1999 by the Citadel/UX development team.\n"
799 "Citadel/UX is free software, covered by the GNU General Public License, and\n"
800 "you are welcome to change it and/or distribute copies of it under certain\n"
801 "conditions. There is absolutely no warranty for this software. Please\n"
802 "read the 'COPYING.txt' file for details.\n\n");
806 openlog("citserver",LOG_PID,LOG_USER);
808 /* Load site-specific parameters */
809 lprintf(7, "Loading citadel.config\n");
813 * Do non system dependent startup functions.
818 * Bind the server to our favorite ports.
820 CtdlRegisterServiceHook(config.c_port_number,
821 citproto_begin_session,
825 * Load any server-side modules (plugins) available here.
827 lprintf(7, "Initializing loadable modules\n");
828 if ((moddir = malloc(strlen(bbs_home_directory) + 9)) != NULL) {
829 sprintf(moddir, "%s/modules", bbs_home_directory);
830 DLoader_Init(moddir);
835 * The rescan pipe exists so that worker threads can be woken up and
836 * told to re-scan the context list for fd's to listen on. This is
837 * necessary, for example, when a context is about to go idle and needs
838 * to get back on that list.
841 lprintf(1, "Can't create rescan pipe!\n");
846 * Set up a fd_set containing all the master sockets to which we
847 * always listen. It's computationally less expensive to just copy
848 * this to a local fd_set when starting a new select() and then add
849 * the client sockets than it is to initialize a new one and then
850 * figure out what to put there.
854 FD_SET(rescan[0], &masterfds);
855 if (rescan[0] > masterhighest) masterhighest = rescan[0];
857 for (serviceptr = ServiceHookTable; serviceptr != NULL;
858 serviceptr = serviceptr->next ) {
859 FD_SET(serviceptr->msock, &masterfds);
860 if (serviceptr->msock > masterhighest) {
861 masterhighest = serviceptr->msock;
867 * Now that we've bound the sockets, change to the BBS user id and its
868 * corresponding group ids
870 if (drop_root_perms) {
871 if ((pw = getpwuid(BBSUID)) == NULL)
872 lprintf(1, "WARNING: getpwuid(%d): %s\n"
873 "Group IDs will be incorrect.\n", BBSUID,
876 initgroups(pw->pw_name, pw->pw_gid);
877 if (setgid(pw->pw_gid))
878 lprintf(3, "setgid(%d): %s\n", pw->pw_gid,
881 lprintf(7, "Changing uid to %d\n", BBSUID);
882 if (setuid(BBSUID) != 0) {
883 lprintf(3, "setuid() failed: %s\n", strerror(errno));
888 * Create the housekeeper thread
890 lprintf(7, "Starting housekeeper thread\n");
891 pthread_attr_init(&attr);
892 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
893 if (pthread_create(&HousekeepingThread, &attr,
894 (void* (*)(void*)) housekeeping_loop, NULL) != 0) {
895 lprintf(1, "Can't create housekeeping thead: %s\n",
901 * Now create a bunch of worker threads.
903 for (i=0; i<(config.c_min_workers-1); ++i) {
904 pthread_attr_init(&attr);
905 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
906 if (pthread_create(&HousekeepingThread, &attr,
907 (void* (*)(void*)) worker_thread, NULL) != 0) {
908 lprintf(1, "Can't create worker thead: %s\n",
913 /* Now this thread can become a worker as well. */
921 * Bind a thread to a context.
923 inline void become_session(struct CitContext *which_con) {
924 pthread_setspecific(MyConKey, (void *)which_con );
930 * This loop just keeps going and going and going...
932 void worker_thread(void) {
936 struct CitContext *ptr;
937 struct CitContext *bind_me = NULL;
940 struct CitContext *con= NULL; /* Temporary context pointer */
941 struct ServiceFunctionHook *serviceptr;
942 struct sockaddr_in fsin; /* Data for master socket */
943 int alen; /* Data for master socket */
944 int ssock; /* Descriptor for client socket */
949 while (!time_to_die) {
952 * A naive implementation would have all idle threads
953 * calling select() and then they'd all wake up at once. We
954 * solve this problem by putting the select() in a critical
955 * section, so only one thread has the opportunity to wake
956 * up. If we wake up on the master socket, create a new
957 * session context; otherwise, just bind the thread to the
958 * context we want and go on our merry way.
961 begin_critical_section(S_I_WANNA_SELECT);
962 SETUP_FD: memcpy(&readfds, &masterfds, sizeof(fd_set) );
963 highest = masterhighest;
964 begin_critical_section(S_SESSION_TABLE);
965 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
966 if (ptr->state == CON_IDLE) {
967 FD_SET(ptr->client_socket, &readfds);
968 if (ptr->client_socket > highest)
969 highest = ptr->client_socket;
972 end_critical_section(S_SESSION_TABLE);
974 tv.tv_sec = 60; /* wake up every minute if no input */
976 retval = select(highest + 1, &readfds, NULL, NULL, &tv);
978 /* Now figure out who made this select() unblock.
979 * First, check for an error or exit condition.
982 end_critical_section(S_I_WANNA_SELECT);
983 lprintf(9, "Exiting (%s)\n", strerror(errno));
987 /* Next, check to see if it's a new client connecting
988 * on the master socket.
990 else for (serviceptr = ServiceHookTable; serviceptr != NULL;
991 serviceptr = serviceptr->next ) {
993 if (FD_ISSET(serviceptr->msock, &readfds)) {
995 ssock = accept(serviceptr->msock,
996 (struct sockaddr *)&fsin, &alen);
998 lprintf(2, "citserver: accept(): %s\n",
1002 lprintf(7, "citserver: "
1003 "New client socket %d\n",
1006 /* New context will be created already
1007 * set up in the CON_EXECUTING state.
1009 con = CreateNewContext();
1011 /* Assign new socket number to it. */
1012 con->client_socket = ssock;
1013 con->h_command_function =
1014 serviceptr->h_command_function;
1016 /* Set the SO_REUSEADDR socket option */
1018 setsockopt(ssock, SOL_SOCKET,
1022 become_session(con);
1024 serviceptr->h_greeting_function();
1025 become_session(NULL);
1026 con->state = CON_IDLE;
1032 /* If the rescan pipe went active, someone is telling this
1033 * thread that the &readfds needs to be refreshed with more
1036 if (!time_to_die) if (FD_ISSET(rescan[0], &readfds)) {
1037 read(rescan[0], &junk, 1);
1041 /* It must be a client socket. Find a context that has data
1042 * waiting on its socket *and* is in the CON_IDLE state.
1046 begin_critical_section(S_SESSION_TABLE);
1047 for (ptr = ContextList;
1048 ( (ptr != NULL) && (bind_me == NULL) );
1050 if ( (FD_ISSET(ptr->client_socket, &readfds))
1051 && (ptr->state == CON_IDLE) ) {
1055 if (bind_me != NULL) {
1056 /* Found one. Stake a claim to it before
1057 * letting anyone else touch the context list.
1059 bind_me->state = CON_EXECUTING;
1062 end_critical_section(S_SESSION_TABLE);
1063 end_critical_section(S_I_WANNA_SELECT);
1065 /* We're bound to a session, now do *one* command */
1066 if (bind_me != NULL) {
1067 become_session(bind_me);
1068 CC->h_command_function();
1069 become_session(NULL);
1070 bind_me->state = CON_IDLE;
1071 if (bind_me->kill_me == 1) {
1072 RemoveContext(bind_me);
1074 write(rescan[1], &junk, 1);
1077 lprintf(9, "Thread found nothing to do!\n");
1081 dead_session_purge();
1082 if ((time(NULL) - last_timer) > 60L) {
1083 last_timer = time(NULL);
1084 PerformSessionHooks(EVT_TIMER);
1088 /* If control reaches this point, the server is shutting down */