4 * Citadel/UX "system dependent" stuff.
5 * See copyright.txt for copyright information.
7 * Here's where we (hopefully) have most parts of the Citadel server that
8 * would need to be altered to run the server in a non-POSIX environment.
10 * If we ever port to a different platform and either have multiple
11 * variants of this file or simply load it up with #ifdefs.
26 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <sys/syslog.h>
32 #if TIME_WITH_SYS_TIME
33 # include <sys/time.h>
37 # include <sys/time.h>
44 #include <netinet/in.h>
57 #include "serv_extensions.h"
58 #include "sysdep_decls.h"
59 #include "citserver.h"
63 #include "housekeeping.h"
65 #include "serv_crypto.h"
67 #ifdef HAVE_SYS_SELECT_H
68 #include <sys/select.h>
75 pthread_mutex_t Critters[MAX_SEMAPHORES]; /* Things needing locking */
76 pthread_key_t MyConKey; /* TSD key for MyContext() */
78 int verbosity = DEFAULT_VERBOSITY; /* Logging level */
80 struct CitContext masterCC;
81 int rescan[2]; /* The Rescan Pipe */
82 time_t last_purge = 0; /* Last dead session purge */
83 static int num_threads = 0; /* Current number of threads */
84 int num_sessions = 0; /* Current number of sessions */
86 fd_set masterfds; /* Master sockets etc. */
89 pthread_t initial_thread; /* tid for main() thread */
91 int syslog_facility = (-1);
95 * lprintf() ... Write logging information
97 * Note: the variable "buf" below needs to be large enough to handle any
98 * log data sent through this function. BE CAREFUL!
100 void lprintf(enum LogLevel loglevel, const char *format, ...) {
104 va_start(arg_ptr, format);
105 vsnprintf(buf, sizeof(buf), format, arg_ptr);
108 if (syslog_facility >= 0) {
109 if (loglevel <= verbosity) {
111 if (CC && CC->cs_pid) {
112 memmove(buf + 6, buf, sizeof(buf) - 6);
113 snprintf(buf, 6, "[%3d]", CC->cs_pid);
116 syslog(loglevel, buf);
119 else if (loglevel <= verbosity) {
124 gettimeofday(&tv, NULL);
125 /* Promote to time_t; types differ on some OSes (like darwin) */
126 unixtime = tv.tv_sec;
127 tim = localtime(&unixtime);
129 * Log provides millisecond accuracy. If you need
130 * microsecond accuracy and your OS supports it, change
131 * %03ld to %06ld and remove " / 1000" after tv.tv_usec.
133 if (CC && CC->cs_pid) {
135 /* Millisecond display */
137 "%04d/%02d/%02d %2d:%02d:%02d.%03ld [%3d] %s",
138 tim->tm_year + 1900, tim->tm_mon + 1,
139 tim->tm_mday, tim->tm_hour, tim->tm_min,
140 tim->tm_sec, (long)tv.tv_usec / 1000,
143 /* Microsecond display */
145 "%04d/%02d/%02d %2d:%02d:%02d.%06ld [%3d] %s",
146 tim->tm_year + 1900, tim->tm_mon + 1,
147 tim->tm_mday, tim->tm_hour, tim->tm_min,
148 tim->tm_sec, (long)tv.tv_usec,
152 /* Millisecond display */
154 "%04d/%02d/%02d %2d:%02d:%02d.%03ld %s",
155 tim->tm_year + 1900, tim->tm_mon + 1,
156 tim->tm_mday, tim->tm_hour, tim->tm_min,
157 tim->tm_sec, (long)tv.tv_usec / 1000, buf);
159 /* Microsecond display */
161 "%04d/%02d/%02d %2d:%02d:%02d.%06ld %s",
162 tim->tm_year + 1900, tim->tm_mon + 1,
163 tim->tm_mday, tim->tm_hour, tim->tm_min,
164 tim->tm_sec, (long)tv.tv_usec, buf);
169 PerformLogHooks(loglevel, buf);
175 * We used to use master_cleanup() as a signal handler to shut down the server.
176 * however, master_cleanup() and the functions it calls do some things that
177 * aren't such a good idea to do from a signal handler: acquiring mutexes,
178 * playing with signal masks on BSDI systems, etc. so instead we install the
179 * following signal handler to set a global variable to inform the main loop
180 * that it's time to call master_cleanup() and exit.
183 volatile int time_to_die = 0;
185 static RETSIGTYPE signal_cleanup(int signum) {
191 * Some initialization stuff...
193 void init_sysdep(void) {
200 /* Set up a bunch of semaphores to be used for critical sections */
201 for (a=0; a<MAX_SEMAPHORES; ++a) {
202 pthread_mutex_init(&Critters[a], NULL);
206 * Set up a place to put thread-specific data.
207 * We only need a single pointer per thread - it points to the
208 * CitContext structure (in the ContextList linked list) of the
209 * session to which the calling thread is currently bound.
211 if (pthread_key_create(&MyConKey, NULL) != 0) {
212 lprintf(CTDL_CRIT, "Can't create TSD key!! %s\n", strerror(errno));
216 * The action for unexpected signals and exceptions should be to
217 * call signal_cleanup() to gracefully shut down the server.
219 signal(SIGINT, signal_cleanup);
220 signal(SIGQUIT, signal_cleanup);
221 signal(SIGHUP, signal_cleanup);
222 signal(SIGTERM, signal_cleanup);
225 * Do not shut down the server on broken pipe signals, otherwise the
226 * whole Citadel service would come down whenever a single client
229 signal(SIGPIPE, SIG_IGN);
234 * Obtain a semaphore lock to begin a critical section.
236 void begin_critical_section(int which_one)
238 /* lprintf(CTDL_DEBUG, "begin_critical_section(%d)\n", which_one); */
239 /* ensure nobody ever tries to do a critical section within a
240 transaction; this could lead to deadlock. */
242 pthread_mutex_lock(&Critters[which_one]);
246 * Release a semaphore lock to end a critical section.
248 void end_critical_section(int which_one)
250 /* lprintf(CTDL_DEBUG, "end_critical_section(%d)\n", which_one); */
251 pthread_mutex_unlock(&Critters[which_one]);
257 * This is a generic function to set up a master socket for listening on
258 * 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;
265 int actual_queue_len;
267 actual_queue_len = queue_len;
268 if (actual_queue_len < 5) actual_queue_len = 5;
270 memset(&sin, 0, sizeof(sin));
271 sin.sin_family = AF_INET;
272 sin.sin_addr.s_addr = INADDR_ANY;
273 sin.sin_port = htons((u_short)port_number);
275 s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
278 lprintf(CTDL_EMERG, "citserver: Can't create a socket: %s\n",
284 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
286 if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
287 lprintf(CTDL_EMERG, "citserver: Can't bind: %s\n",
293 if (listen(s, actual_queue_len) < 0) {
294 lprintf(CTDL_EMERG, "citserver: Can't listen: %s\n", strerror(errno));
305 * Create a Unix domain socket and listen on it
307 int ig_uds_server(char *sockpath, int queue_len)
309 struct sockaddr_un addr;
312 int actual_queue_len;
314 actual_queue_len = queue_len;
315 if (actual_queue_len < 5) actual_queue_len = 5;
317 i = unlink(sockpath);
318 if (i != 0) if (errno != ENOENT) {
319 lprintf(CTDL_EMERG, "citserver: can't unlink %s: %s\n",
320 sockpath, strerror(errno));
324 memset(&addr, 0, sizeof(addr));
325 addr.sun_family = AF_UNIX;
326 safestrncpy(addr.sun_path, sockpath, sizeof addr.sun_path);
328 s = socket(AF_UNIX, SOCK_STREAM, 0);
330 lprintf(CTDL_EMERG, "citserver: Can't create a socket: %s\n",
335 if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
336 lprintf(CTDL_EMERG, "citserver: Can't bind: %s\n",
341 if (listen(s, actual_queue_len) < 0) {
342 lprintf(CTDL_EMERG, "citserver: Can't listen: %s\n", strerror(errno));
346 chmod(sockpath, 0777);
353 * Return a pointer to the CitContext structure bound to the thread which
354 * called this function. If there's no such binding (for example, if it's
355 * called by the housekeeper thread) then a generic 'master' CC is returned.
357 * It's inlined because it's used *VERY* frequently.
359 INLINE struct CitContext *MyContext(void) {
360 return ((pthread_getspecific(MyConKey) == NULL)
362 : (struct CitContext *) pthread_getspecific(MyConKey)
368 * Initialize a new context and place it in the list. The session number
369 * used to be the PID (which is why it's called cs_pid), but that was when we
370 * had one process per session. Now we just assign them sequentially, starting
371 * at 1 (don't change it to 0 because masterCC uses 0) and re-using them when
372 * sessions terminate.
374 struct CitContext *CreateNewContext(void) {
375 struct CitContext *me, *ptr;
377 me = (struct CitContext *) malloc(sizeof(struct CitContext));
379 lprintf(CTDL_ALERT, "citserver: can't allocate memory!!\n");
382 memset(me, 0, sizeof(struct CitContext));
384 /* The new context will be created already in the CON_EXECUTING state
385 * in order to prevent another thread from grabbing it while it's
388 me->state = CON_EXECUTING;
392 * Generate a unique session number and insert this context into
395 begin_critical_section(S_SESSION_TABLE);
397 if (ContextList == NULL) {
403 else if (ContextList->cs_pid > 1) {
404 me->next = ContextList;
410 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
411 if (ptr->next == NULL) {
413 me->cs_pid = ptr->cs_pid + 1;
417 else if (ptr->next->cs_pid > (ptr->cs_pid+1)) {
418 me->next = ptr->next;
420 me->cs_pid = ptr->cs_pid + 1;
426 DONE: ++num_sessions;
427 end_critical_section(S_SESSION_TABLE);
433 * buffer_output() ... tell client_write to buffer all output until
434 * instructed to dump it all out later
436 void buffer_output(void) {
437 if (CC->buffering == 0) {
440 CC->output_buffer = malloc(SIZ);
445 * unbuffer_output() ... dump out all that output we've been buffering.
447 void unbuffer_output(void) {
448 if (CC->buffering == 1) {
450 client_write(CC->output_buffer, CC->buffer_len);
451 free(CC->output_buffer);
452 CC->output_buffer = NULL;
460 * client_write() ... Send binary data to the client.
462 void client_write(char *buf, int nbytes)
464 int bytes_written = 0;
467 int old_buffer_len = 0;
469 if (CC->redirect_fp != NULL) {
470 fwrite(buf, nbytes, 1, CC->redirect_fp);
474 if (CC->redirect_sock > 0) {
475 sock = CC->redirect_sock; /* and continue below... */
478 sock = CC->client_socket;
481 /* If we're buffering for later, do that now. */
483 old_buffer_len = CC->buffer_len;
484 CC->buffer_len += nbytes;
485 CC->output_buffer = realloc(CC->output_buffer, CC->buffer_len);
486 memcpy(&CC->output_buffer[old_buffer_len], buf, nbytes);
490 /* Ok, at this point we're not buffering. Go ahead and write. */
493 if (CC->redirect_ssl) {
494 client_write_ssl(buf, nbytes);
499 while (bytes_written < nbytes) {
500 retval = write(sock, &buf[bytes_written],
501 nbytes - bytes_written);
503 lprintf(CTDL_ERR, "client_write() failed: %s\n",
505 if (sock == CC->client_socket) CC->kill_me = 1;
508 bytes_written = bytes_written + retval;
514 * cprintf() ... Send formatted printable data to the client. It is
515 * implemented in terms of client_write() but remains in
516 * sysdep.c in case we port to somewhere without va_args...
518 void cprintf(const char *format, ...) {
522 va_start(arg_ptr, format);
523 if (vsnprintf(buf, sizeof buf, format, arg_ptr) == -1)
524 buf[sizeof buf - 2] = '\n';
525 client_write(buf, strlen(buf));
531 * Read data from the client socket.
533 * 1 Requested number of bytes has been read.
534 * 0 Request timed out.
535 * -1 The socket is broken.
536 * If the socket breaks, the session will be terminated.
538 int client_read_to(char *buf, int bytes, int timeout)
546 if (CC->redirect_ssl) {
547 return (client_read_ssl(buf, bytes, timeout));
553 FD_SET(CC->client_socket, &rfds);
557 retval = select( (CC->client_socket)+1,
558 &rfds, NULL, NULL, &tv);
560 if (FD_ISSET(CC->client_socket, &rfds) == 0) {
564 rlen = read(CC->client_socket, &buf[len], bytes-len);
566 lprintf(CTDL_ERR, "client_read() failed: %s\n",
577 * Read data from the client socket with default timeout.
578 * (This is implemented in terms of client_read_to() and could be
579 * justifiably moved out of sysdep.c)
581 INLINE int client_read(char *buf, int bytes)
583 return(client_read_to(buf, bytes, config.c_sleeping));
588 * client_gets() ... Get a LF-terminated line of text from the client.
589 * (This is implemented in terms of client_read() and could be
590 * justifiably moved out of sysdep.c)
592 int client_gets(char *buf)
596 /* Read one character at a time.
599 retval = client_read(&buf[i], 1);
600 if (retval != 1 || buf[i] == '\n' || i == (SIZ-1))
604 /* If we got a long line, discard characters until the newline.
607 while (buf[i] != '\n' && retval == 1)
608 retval = client_read(&buf[i], 1);
610 /* Strip the trailing newline and any trailing nonprintables (cr's)
613 while ((strlen(buf)>0)&&(!isprint(buf[strlen(buf)-1])))
614 buf[strlen(buf)-1] = 0;
615 if (retval < 0) strcpy(buf, "000");
622 * The system-dependent part of master_cleanup() - close the master socket.
624 void sysdep_master_cleanup(void) {
625 struct ServiceFunctionHook *serviceptr;
628 * close all protocol master sockets
630 for (serviceptr = ServiceHookTable; serviceptr != NULL;
631 serviceptr = serviceptr->next ) {
633 if (serviceptr->tcp_port > 0)
634 lprintf(CTDL_INFO, "Closing listener on port %d\n",
635 serviceptr->tcp_port);
637 if (serviceptr->sockpath != NULL)
638 lprintf(CTDL_INFO, "Closing listener on '%s'\n",
639 serviceptr->sockpath);
641 close(serviceptr->msock);
643 /* If it's a Unix domain socket, remove the file. */
644 if (serviceptr->sockpath != NULL) {
645 unlink(serviceptr->sockpath);
652 * Terminate another session.
653 * (This could justifiably be moved out of sysdep.c because it
654 * no longer does anything that is system-dependent.)
656 void kill_session(int session_to_kill) {
657 struct CitContext *ptr;
659 begin_critical_section(S_SESSION_TABLE);
660 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
661 if (ptr->cs_pid == session_to_kill) {
665 end_critical_section(S_SESSION_TABLE);
672 * Start running as a daemon. Only close stdio if do_close_stdio is set.
674 void start_daemon(int do_close_stdio) {
675 if (do_close_stdio) {
680 signal(SIGHUP,SIG_IGN);
681 signal(SIGINT,SIG_IGN);
682 signal(SIGQUIT,SIG_IGN);
683 if (fork()!=0) exit(0);
689 * Generic routine to convert a login name to a full name (gecos)
690 * Returns nonzero if a conversion took place
692 int convert_login(char NameToConvert[]) {
696 pw = getpwnam(NameToConvert);
701 strcpy(NameToConvert, pw->pw_gecos);
702 for (a=0; a<strlen(NameToConvert); ++a) {
703 if (NameToConvert[a] == ',') NameToConvert[a] = 0;
709 struct worker_node *worker_list = NULL;
713 * create a worker thread. this function must always be called from within
714 * an S_WORKER_LIST critical section!
716 void create_worker(void) {
718 struct worker_node *n;
721 n = malloc(sizeof(struct worker_node));
723 lprintf(CTDL_EMERG, "can't allocate worker_node, exiting\n");
728 if ((ret = pthread_attr_init(&attr))) {
729 lprintf(CTDL_EMERG, "pthread_attr_init: %s\n", strerror(ret));
734 /* we seem to need something bigger than FreeBSD's default 64k stack */
736 if ((ret = pthread_attr_setstacksize(&attr, 128 * 1024))) {
737 lprintf(CTDL_EMERG, "pthread_attr_setstacksize: %s\n", strerror(ret));
742 if ((ret = pthread_create(&n->tid, &attr, worker_thread, NULL) != 0))
745 lprintf(CTDL_ALERT, "Can't create worker thread: %s\n",
749 n->next = worker_list;
756 * Purge all sessions which have the 'kill_me' flag set.
757 * This function has code to prevent it from running more than once every
758 * few seconds, because running it after every single unbind would waste a lot
759 * of CPU time and keep the context list locked too much.
761 * After that's done, we raise or lower the size of the worker thread pool
762 * if such an action is appropriate.
764 void dead_session_purge(void) {
765 struct CitContext *ptr, *rem;
766 struct worker_node **node, *tmp;
769 if ( (time(NULL) - last_purge) < 5 ) return; /* Too soon, go away */
774 begin_critical_section(S_SESSION_TABLE);
775 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
776 if ( (ptr->state == CON_IDLE) && (ptr->kill_me) ) {
780 end_critical_section(S_SESSION_TABLE);
782 /* RemoveContext() enters its own S_SESSION_TABLE critical
783 * section, so we have to do it like this.
786 lprintf(CTDL_DEBUG, "Purging session %d\n", rem->cs_pid);
790 } while (rem != NULL);
793 /* Raise or lower the size of the worker thread pool if such
794 * an action is appropriate.
797 self = pthread_self();
799 if ( (num_sessions > num_threads)
800 && (num_threads < config.c_max_workers) ) {
801 begin_critical_section(S_WORKER_LIST);
803 end_critical_section(S_WORKER_LIST);
806 /* don't let the initial thread die since it's responsible for
807 waiting for all the other threads to terminate. */
808 else if ( (num_sessions < num_threads)
809 && (num_threads > config.c_min_workers)
810 && (self != initial_thread) ) {
812 begin_critical_section(S_WORKER_LIST);
815 /* we're exiting before server shutdown... unlink ourself from
816 the worker list and detach our thread to avoid memory leaks
819 for (node = &worker_list; *node != NULL; node = &(*node)->next)
820 if ((*node)->tid == self) {
822 *node = (*node)->next;
827 pthread_detach(self);
828 end_critical_section(S_WORKER_LIST);
839 * Redirect a session's output to a file or socket.
840 * This function may be called with a file handle *or* a socket (but not
841 * both). Call with neither to return output to its normal client socket.
843 void CtdlRedirectOutput(FILE *fp, int sock) {
845 if (fp != NULL) CC->redirect_fp = fp;
846 else CC->redirect_fp = NULL;
848 if (sock > 0) CC->redirect_sock = sock;
849 else CC->redirect_sock = (-1);
855 * masterCC is the context we use when not attached to a session. This
856 * function initializes it.
858 void InitializeMasterCC(void) {
859 memset(&masterCC, 0, sizeof(struct CitContext));
860 masterCC.internal_pgm = 1;
867 * Set up a fd_set containing all the master sockets to which we
868 * always listen. It's computationally less expensive to just copy
869 * this to a local fd_set when starting a new select() and then add
870 * the client sockets than it is to initialize a new one and then
871 * figure out what to put there.
873 void init_master_fdset(void) {
874 struct ServiceFunctionHook *serviceptr;
877 lprintf(CTDL_DEBUG, "Initializing master fdset\n");
882 lprintf(CTDL_DEBUG, "Will listen on rescan pipe %d\n", rescan[0]);
883 FD_SET(rescan[0], &masterfds);
884 if (rescan[0] > masterhighest) masterhighest = rescan[0];
886 for (serviceptr = ServiceHookTable; serviceptr != NULL;
887 serviceptr = serviceptr->next ) {
888 m = serviceptr->msock;
889 lprintf(CTDL_DEBUG, "Will listen on master socket %d\n", m);
890 FD_SET(m, &masterfds);
891 if (m > masterhighest) {
895 lprintf(CTDL_DEBUG, "masterhighest = %d\n", masterhighest);
900 * Bind a thread to a context. (It's inline merely to speed things up.)
902 INLINE void become_session(struct CitContext *which_con) {
903 pthread_setspecific(MyConKey, (void *)which_con );
909 * This loop just keeps going and going and going...
911 void *worker_thread(void *arg) {
915 /* This is synchronized below; it helps implement round robin mode */
916 static struct CitContext* next_session = NULL;
917 struct CitContext *ptr;
918 struct CitContext *bind_me = NULL;
921 struct CitContext *con= NULL; /* Temporary context pointer */
922 struct ServiceFunctionHook *serviceptr;
923 int ssock; /* Descriptor for client socket */
930 while (!time_to_die) {
933 * A naive implementation would have all idle threads
934 * calling select() and then they'd all wake up at once
935 * (known in computer science as the "thundering herd"
936 * problem). We solve this problem by putting the select()
937 * in a critical section, so only one thread has the
938 * opportunity to wake up. If we wake up on a master
939 * socket, create a new session context; otherwise, just
940 * bind the thread to the context we want and go on our
944 /* make doubly sure we're not holding any stale db handles
945 * which might cause a deadlock.
949 begin_critical_section(S_I_WANNA_SELECT);
950 SETUP_FD: memcpy(&readfds, &masterfds, sizeof masterfds);
951 highest = masterhighest;
952 begin_critical_section(S_SESSION_TABLE);
953 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
954 if (ptr->state == CON_IDLE) {
955 FD_SET(ptr->client_socket, &readfds);
956 if (ptr->client_socket > highest)
957 highest = ptr->client_socket;
960 end_critical_section(S_SESSION_TABLE);
962 tv.tv_sec = 1; /* wake up every second if no input */
967 retval = select(highest + 1, &readfds, NULL, NULL, &tv);
969 end_critical_section(S_I_WANNA_SELECT);
973 /* Now figure out who made this select() unblock.
974 * First, check for an error or exit condition.
977 if (errno != EINTR) {
978 lprintf(CTDL_EMERG, "Exiting (%s)\n", strerror(errno));
980 } else if (!time_to_die)
984 /* Next, check to see if it's a new client connecting
985 * on a master socket.
987 else for (serviceptr = ServiceHookTable; serviceptr != NULL;
988 serviceptr = serviceptr->next ) {
990 if (FD_ISSET(serviceptr->msock, &readfds)) {
991 ssock = accept(serviceptr->msock, NULL, 0);
994 "citserver: accept(): %s\n",
999 "New client socket %d\n",
1002 /* New context will be created already
1003 * set up in the CON_EXECUTING state.
1005 con = CreateNewContext();
1007 /* Assign new socket number to it. */
1008 con->client_socket = ssock;
1009 con->h_command_function =
1010 serviceptr->h_command_function;
1012 /* Determine whether local socket */
1013 if (serviceptr->sockpath != NULL)
1014 con->is_local_socket = 1;
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
1037 end_critical_section(S_I_WANNA_SELECT);
1041 if (FD_ISSET(rescan[0], &readfds)) {
1042 read(rescan[0], &junk, 1);
1046 /* It must be a client socket. Find a context that has data
1047 * waiting on its socket *and* is in the CON_IDLE state.
1051 begin_critical_section(S_SESSION_TABLE);
1053 * We start where we left off. If we get to the end
1054 * we'll start from the beginning again, then give up
1055 * if we still don't find anything. This ensures
1056 * that all contexts get a more-or-less equal chance
1057 * to run. And yes, I did add a goto to the code. -IO
1059 find_session: if (next_session == NULL)
1060 next_session = ContextList;
1061 for (ptr = next_session;
1062 ( (ptr != NULL) && (bind_me == NULL) );
1064 if ( (FD_ISSET(ptr->client_socket, &readfds))
1065 && (ptr->state == CON_IDLE) ) {
1069 if (bind_me != NULL) {
1070 /* Found one. Stake a claim to it before
1071 * letting anyone else touch the context list.
1073 bind_me->state = CON_EXECUTING;
1074 next_session = bind_me->next;
1075 } else if (next_session == ContextList) {
1076 next_session = NULL;
1078 if (bind_me == NULL && next_session != NULL) {
1079 next_session = NULL;
1083 end_critical_section(S_SESSION_TABLE);
1084 end_critical_section(S_I_WANNA_SELECT);
1086 /* We're bound to a session, now do *one* command */
1087 if (bind_me != NULL) {
1088 become_session(bind_me);
1089 CC->h_command_function();
1090 become_session(NULL);
1091 bind_me->state = CON_IDLE;
1092 if (bind_me->kill_me == 1) {
1093 RemoveContext(bind_me);
1095 write(rescan[1], &junk, 1);
1099 dead_session_purge();
1101 check_sched_shutdown();
1104 /* If control reaches this point, the server is shutting down */
1114 * Translate text facility name to syslog.h defined value.
1116 int SyslogFacility(char *name)
1125 { LOG_KERN, "kern" },
1126 { LOG_USER, "user" },
1127 { LOG_MAIL, "mail" },
1128 { LOG_DAEMON, "daemon" },
1129 { LOG_AUTH, "auth" },
1130 { LOG_SYSLOG, "syslog" },
1132 { LOG_NEWS, "news" },
1133 { LOG_UUCP, "uucp" },
1134 { LOG_LOCAL0, "local0" },
1135 { LOG_LOCAL1, "local1" },
1136 { LOG_LOCAL2, "local2" },
1137 { LOG_LOCAL3, "local3" },
1138 { LOG_LOCAL4, "local4" },
1139 { LOG_LOCAL5, "local5" },
1140 { LOG_LOCAL6, "local6" },
1141 { LOG_LOCAL7, "local7" },
1144 for(i = 0; facTbl[i].name != NULL; i++) {
1145 if(!strcasecmp(name, facTbl[i].name))
1146 return facTbl[i].facility;