1 // This started as a portability layer, but then everything got more standard.
2 // Most of it handles network communication.
4 // Copyright (c) 1987-2023 by the citadel.org team
6 // This program is open source software. Use, duplication, or disclosure
7 // is subject to the terms of the GNU General Public License, version 3.
17 #include <sys/syslog.h>
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
24 #include <arpa/inet.h>
25 #include <netinet/tcp.h>
26 #include <arpa/inet.h>
27 #define SHOW_ME_VAPPEND_PRINTF
28 #include <libcitadel.h>
29 #include "citserver.h"
31 #include "ctdl_module.h"
32 #include "sysdep_decls.h"
33 #include "modules/crypto/serv_crypto.h" // Needed for init_ssl, client_write_ssl, client_read_ssl
34 #include "housekeeping.h"
37 // Signal handler to shut down the server.
38 volatile int exit_signal = 0;
39 volatile int shutdown_and_halt = 0;
40 volatile int restart_server = 0;
41 volatile int running_as_daemon = 0;
44 static RETSIGTYPE signal_cleanup(int signum) {
45 syslog(LOG_DEBUG, "sysdep: caught signal %d", signum);
46 signal(SIGINT, SIG_DFL);
47 signal(SIGHUP, SIG_DFL);
48 signal(SIGTERM, SIG_DFL);
49 //signal(SIGSEGV, SIG_DFL);
51 server_shutting_down = 1;
52 master_cleanup(signum);
56 // Some initialization stuff...
57 void init_sysdep(void) {
60 // Avoid vulnerabilities related to FD_SETSIZE if we can.
64 getrlimit(RLIMIT_NOFILE, &rl);
65 rl.rlim_cur = FD_SETSIZE;
66 rl.rlim_max = FD_SETSIZE;
67 setrlimit(RLIMIT_NOFILE, &rl);
71 // If we've got OpenSSL, we're going to use it.
76 if (pthread_key_create(&MyConKey, NULL) != 0) { // TSD for sessions
77 syslog(LOG_CRIT, "sysdep: can't create TSD key: %m");
78 exit(CTDLEXIT_THREAD);
81 // Interript, hangup, and terminate signals should cause the server to shut down.
83 sigaddset(&set, SIGINT);
84 sigaddset(&set, SIGHUP);
85 sigaddset(&set, SIGTERM);
86 //sigaddset(&set, SIGSEGV);
87 sigprocmask(SIG_UNBLOCK, &set, NULL);
89 signal(SIGINT, signal_cleanup);
90 signal(SIGHUP, signal_cleanup);
91 signal(SIGTERM, signal_cleanup);
92 //signal(SIGSEGV, signal_cleanup);
94 // Do not shut down the server on broken pipe signals, otherwise the
95 // whole Citadel service would come down whenever a single client
97 signal(SIGPIPE, SIG_IGN);
101 // This is a generic function to set up a master socket for listening on
102 // a TCP port. The server shuts down if the bind fails. (IPv4/IPv6 version)
104 // ip_addr IP address to bind
105 // port_number port number to bind
106 // queue_len number of incoming connections to allow in the queue
107 int ctdl_tcp_server(char *ip_addr, int port_number, int queue_len) {
109 struct sockaddr_in6 sin6;
110 struct sockaddr_in sin4;
114 memset(&sin6, 0, sizeof(sin6));
115 memset(&sin4, 0, sizeof(sin4));
116 sin6.sin6_family = AF_INET6;
117 sin4.sin_family = AF_INET;
119 if ( (ip_addr == NULL) // any IPv6
120 || (IsEmptyStr(ip_addr))
121 || (!strcmp(ip_addr, "*"))
122 || (!strcmp(ip_addr, "::"))
125 sin6.sin6_addr = in6addr_any;
127 else if (!strcmp(ip_addr, "0.0.0.0")) { // any IPv4
129 sin4.sin_addr.s_addr = INADDR_ANY;
131 else if ((strchr(ip_addr, '.')) && (!strchr(ip_addr, ':'))) { // specific IPv4
133 if (inet_pton(AF_INET, ip_addr, &sin4.sin_addr) <= 0) {
134 syslog(LOG_ALERT, "tcpserver: inet_pton: %m");
138 else { // specific IPv6
140 if (inet_pton(AF_INET6, ip_addr, &sin6.sin6_addr) <= 0) {
141 syslog(LOG_ALERT, "tcpserver: inet_pton: %m");
146 if (port_number == 0) {
147 syslog(LOG_ALERT, "tcpserver: no port number was specified");
150 sin6.sin6_port = htons((u_short) port_number);
151 sin4.sin_port = htons((u_short) port_number);
153 p = getprotobyname("tcp");
155 syslog(LOG_ALERT, "tcpserver: getprotobyname: %m");
159 s = socket( ((ip_version == 6) ? PF_INET6 : PF_INET), SOCK_STREAM, (p->p_proto));
161 syslog(LOG_ALERT, "tcpserver: socket: %m");
164 // Set some socket options that make sense.
166 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
168 if (ip_version == 6) {
169 b = bind(s, (struct sockaddr *) &sin6, sizeof(sin6));
172 b = bind(s, (struct sockaddr *) &sin4, sizeof(sin4));
176 syslog(LOG_ALERT, "tcpserver: bind: %m");
180 fcntl(s, F_SETFL, O_NONBLOCK);
182 if (listen(s, ((queue_len >= 5) ? queue_len : 5) ) < 0) {
183 syslog(LOG_ALERT, "tcpserver: listen: %m");
190 // Create a Unix domain socket and listen on it
191 int ctdl_uds_server(char *sockpath, int queue_len) {
192 struct sockaddr_un addr;
195 int actual_queue_len;
197 actual_queue_len = queue_len;
198 if (actual_queue_len < 5) actual_queue_len = 5;
200 i = unlink(sockpath);
201 if ((i != 0) && (errno != ENOENT)) {
202 syslog(LOG_ERR, "udsserver: %m");
206 memset(&addr, 0, sizeof(addr));
207 addr.sun_family = AF_UNIX;
208 safestrncpy(addr.sun_path, sockpath, sizeof addr.sun_path);
210 s = socket(AF_UNIX, SOCK_STREAM, 0);
212 syslog(LOG_ERR, "udsserver: socket: %m");
216 if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
217 syslog(LOG_ERR, "udsserver: bind: %m");
221 // set to nonblock - we need this for some obscure situations
222 if (fcntl(s, F_SETFL, O_NONBLOCK) < 0) {
223 syslog(LOG_ERR, "udsserver: fcntl: %m");
228 if (listen(s, actual_queue_len) < 0) {
229 syslog(LOG_ERR, "udsserver: listen: %m");
233 chmod(sockpath, S_ISGID|S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH);
238 // The following functions implement output buffering on operating systems which
239 // support it (such as Linux and various BSD flavors).
242 # define HAVE_TCP_BUFFERING
245 # define HAVE_TCP_BUFFERING
246 # define TCP_CORK TCP_NOPUSH
249 #endif // HAVE_DARWIN
251 static unsigned on = 1, off = 0;
253 void buffer_output(void) {
254 #ifdef HAVE_TCP_BUFFERING
256 if (!CC->redirect_ssl)
258 setsockopt(CC->client_socket, IPPROTO_TCP, TCP_CORK, &on, 4);
262 void unbuffer_output(void) {
263 #ifdef HAVE_TCP_BUFFERING
265 if (!CC->redirect_ssl)
267 setsockopt(CC->client_socket, IPPROTO_TCP, TCP_CORK, &off, 4);
271 void flush_output(void) {
272 #ifdef HAVE_TCP_BUFFERING
273 setsockopt(CC->client_socket, IPPROTO_TCP, TCP_CORK, &off, 4);
274 setsockopt(CC->client_socket, IPPROTO_TCP, TCP_CORK, &on, 4);
279 // close the client socket
280 void client_close(void) {
282 if (CC->client_socket <= 0) return;
283 syslog(LOG_DEBUG, "sysdep: closing socket %d", CC->client_socket);
284 close(CC->client_socket);
285 CC->client_socket = -1 ;
289 // Send binary data to the client.
290 int client_write(const char *buf, int nbytes) {
291 int bytes_written = 0;
293 #ifndef HAVE_TCP_BUFFERING
294 int old_buffer_len = 0;
300 if (nbytes < 1) return(0);
303 if (Ctx->redirect_buffer != NULL) {
304 StrBufAppendBufPlain(Ctx->redirect_buffer, buf, nbytes, 0);
309 if (Ctx->redirect_ssl) {
310 client_write_ssl(buf, nbytes);
314 if (Ctx->client_socket == -1) return -1;
316 fdflags = fcntl(Ctx->client_socket, F_GETFL);
318 while ((bytes_written < nbytes) && (Ctx->client_socket != -1)){
319 if ((fdflags & O_NONBLOCK) == O_NONBLOCK) {
321 FD_SET(Ctx->client_socket, &wset);
322 if (select(1, NULL, &wset, NULL, NULL) == -1) {
323 if (errno == EINTR) {
324 syslog(LOG_DEBUG, "sysdep: client_write(%d bytes) select() interrupted.", nbytes-bytes_written);
325 if (server_shutting_down) {
326 CC->kill_me = KILLME_SELECT_INTERRUPTED;
330 // can't trust fd's and stuff so we need to re-create them
335 syslog(LOG_ERR, "sysdep: client_write(%d bytes) select failed: %m", nbytes - bytes_written);
337 Ctx->kill_me = KILLME_SELECT_FAILED;
343 retval = write(Ctx->client_socket, &buf[bytes_written], nbytes - bytes_written);
345 syslog(LOG_ERR, "sysdep: client_write(%d bytes) failed: %m", nbytes - bytes_written);
347 Ctx->kill_me = KILLME_WRITE_FAILED;
350 bytes_written = bytes_written + retval;
356 void cputbuf(const StrBuf *Buf) {
357 client_write(ChrPtr(Buf), StrLength(Buf));
361 // Send formatted printable data to the client.
362 // Implemented in terms of client_write() so it's technically not sysdep...
363 void cprintf(const char *format, ...) {
368 va_start(arg_ptr, format);
369 rc = vsnprintf(buf, sizeof buf, format, arg_ptr);
371 syslog(LOG_ERR,"Console output error occured. Format: %s",format);
373 if (rc >= sizeof buf) {
374 // Output was truncated.
375 // Chop at the end of the buffer
376 buf[sizeof buf - 2] = '\n';
377 buf[sizeof buf - 1] = 0;
379 client_write(buf, strlen(buf));
385 // Read data from the client socket.
387 // sock socket fd to read from
388 // buf buffer to read into
389 // bytes number of bytes to read
390 // timeout Number of seconds to wait before timing out
392 // Possible return values:
393 // 1 Requested number of bytes has been read.
394 // 0 Request timed out.
395 // -1 Connection is broken, or other error.
396 int client_read_blob(StrBuf *Target, int bytes, int timeout) {
401 if (CC->redirect_ssl) {
402 retval = client_read_sslblob(Target, bytes, timeout);
404 syslog(LOG_ERR, "sysdep: client_read_blob() failed");
410 retval = StrBufReadBLOBBuffered(Target,
412 &CC->RecvBuf.ReadWritePointer,
420 syslog(LOG_ERR, "sysdep: client_read_blob() failed: %s", Error);
429 // to make client_read_random_blob() more efficient, increase buffer size.
430 // just use in greeting function, else your buffer may be flushed
431 void client_set_inbound_buf(long N) {
432 FlushStrBuf(CC->RecvBuf.Buf);
433 ReAdjustEmptyBuf(CC->RecvBuf.Buf, N * SIZ, N * SIZ);
437 int client_read_random_blob(StrBuf *Target, int timeout) {
440 rc = client_read_blob(Target, 1, timeout);
445 len = StrLength(CC->RecvBuf.Buf);
446 pch = ChrPtr(CC->RecvBuf.Buf);
449 if (CC->RecvBuf.ReadWritePointer != NULL) {
450 len -= CC->RecvBuf.ReadWritePointer - pch;
451 pch = CC->RecvBuf.ReadWritePointer;
453 StrBufAppendBufPlain(Target, pch, len, 0);
454 FlushStrBuf(CC->RecvBuf.Buf);
455 CC->RecvBuf.ReadWritePointer = NULL;
456 return StrLength(Target);
465 int client_read_to(char *buf, int bytes, int timeout) {
468 rc = client_read_blob(CC->MigrateBuf, bytes, timeout);
475 ChrPtr(CC->MigrateBuf),
476 StrLength(CC->MigrateBuf) + 1);
477 FlushStrBuf(CC->MigrateBuf);
483 int HaveMoreLinesWaiting(CitContext *ctx) {
484 if ( (ctx->kill_me != 0)
485 || ( (ctx->RecvBuf.ReadWritePointer == NULL)
486 && (StrLength(ctx->RecvBuf.Buf) == 0)
487 && (ctx->client_socket != -1))
495 // Read data from the client socket with default timeout.
496 // (This is implemented in terms of client_read_to() and could be
497 // justifiably moved out of sysdep.c)
498 INLINE int client_read(char *buf, int bytes) {
499 return(client_read_to(buf, bytes, CtdlGetConfigInt("c_sleeping")));
503 int CtdlClientGetLine(StrBuf *Target) {
509 if (CC->redirect_ssl) {
510 rc = client_readline_sslbuffer(Target, CC->RecvBuf.Buf, &CC->RecvBuf.ReadWritePointer, 1);
516 rc = StrBufTCP_read_buffered_line_fast(Target,
518 &CC->RecvBuf.ReadWritePointer,
529 // Get a LF-terminated line of text from the client.
530 // (This is implemented in terms of client_read() and could be
531 // justifiably moved out of sysdep.c)
532 int client_getln(char *buf, int bufsize) {
536 retval = CtdlClientGetLine(CC->MigrateBuf);
541 i = StrLength(CC->MigrateBuf);
542 pCh = ChrPtr(CC->MigrateBuf);
543 // Strip the trailing LF, and the trailing CR if present.
547 && ( (pCh[i - 1]==13)
548 || ( pCh[i - 1]==10)) ) {
554 FlushStrBuf(CC->MigrateBuf);
556 safestrncpy(&buf[i], "000", bufsize - i);
563 void supervisor_process_shutdown(int signum) {
564 kill(current_child, signum);
565 unlink(file_pid_file);
570 int nFireUpsNonRestart = 0;
573 // Start running as a daemon.
574 void start_daemon(int unused) {
581 // Close stdin/stdout/stderr and replace them with /dev/null.
582 // We don't just call close() because we don't want these fd's
583 // to be reused for other files.
589 signal(SIGHUP, SIG_IGN);
590 signal(SIGINT, SIG_IGN);
591 signal(SIGQUIT, SIG_IGN);
595 if ( (freopen("/dev/null", "r", stdin) != stdin) ||
596 (freopen("/dev/null", "w", stdout) != stdout) ||
597 (freopen("/dev/null", "w", stderr) != stderr)
599 syslog(LOG_ERR, "sysdep: unable to reopen stdio: %m");
603 current_child = fork();
604 signal(SIGTERM, supervisor_process_shutdown);
605 if (current_child < 0) {
609 else if (current_child == 0) {
610 return; // continue starting citadel.
613 fp = fopen(file_pid_file, "w");
615 fprintf(fp, ""F_PID_T"\n", getpid());
618 waitpid(current_child, &status, 0);
620 nFireUpsNonRestart = nFireUps;
622 // Exit code 0 means the watcher should exit
623 if (WIFEXITED(status) && (WEXITSTATUS(status) == CTDLEXIT_SHUTDOWN)) {
627 // Exit code 101-109 means the watcher should exit
628 else if (WIFEXITED(status) && (WEXITSTATUS(status) >= 101) && (WEXITSTATUS(status) <= 109)) {
632 // Any other exit code, or no exit code, means we should restart.
636 ForkedPid = current_child;
639 } while (do_restart);
641 unlink(file_pid_file);
642 exit(WEXITSTATUS(status));
646 void checkcrash(void) {
647 if (nFireUpsNonRestart != nFireUps) {
649 CrashMail = NewStrBuf();
650 syslog(LOG_ALERT, "sysdep: posting crash message");
651 StrBufPrintf(CrashMail,
653 " The Citadel server process (citserver) terminated unexpectedly."
655 " This could be the result of a bug in the server program, or some external "
657 " You can obtain more information about this by enabling core dumps.\n \n"
658 " For more information, please see:\n \n"
659 " http://citadel.org/doku.php?id=faq:mastering_your_os:gdb#how.do.i.make.my.system.produce.core-files"
662 " If you have already done this, the core dump is likely to be found at %score.%d\n"
664 ctdl_run_dir, ForkedPid);
665 CtdlAideMessage(ChrPtr(CrashMail), "Citadel server process terminated unexpectedly");
666 FreeStrBuf(&CrashMail);
671 // Generic routine to convert a login name to a full name (gecos)
672 // Returns nonzero if a conversion took place
673 int convert_login(char NameToConvert[]) {
677 pw = getpwnam(NameToConvert);
682 strcpy(NameToConvert, pw->pw_gecos);
683 for (a=0; a<strlen(NameToConvert); ++a) {
684 if (NameToConvert[a] == ',') NameToConvert[a] = 0;
691 void HuntBadSession(void) {
696 struct ServiceFunctionHook *serviceptr;
698 // Next, add all of the client sockets
699 begin_critical_section(S_SESSION_TABLE);
700 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
701 if ((ptr->state == CON_SYS) && (ptr->client_socket == 0))
703 // Initialize the fdset.
706 tv.tv_sec = 0; // wake up every second if no input
709 // Don't select on dead sessions, only truly idle ones
710 if ( (ptr->state == CON_IDLE)
711 && (ptr->kill_me == 0)
712 && (ptr->client_socket > 0)
714 FD_SET(ptr->client_socket, &readfds);
715 if (ptr->client_socket > highest)
716 highest = ptr->client_socket;
718 if ((select(highest + 1, &readfds, NULL, NULL, &tv) < 0) && (errno == EBADF)) {
721 "sysdep: killing session CC[%d] bad FD: [%d] User[%s] Host[%s:%s]",
729 ptr->client_socket = -1;
734 end_critical_section(S_SESSION_TABLE);
736 // First, add the various master sockets to the fdset.
737 for (serviceptr = ServiceHookTable; serviceptr != NULL; serviceptr = serviceptr->next ) {
739 // Initialize the fdset.
741 tv.tv_sec = 0; // wake up every second if no input
744 FD_SET(serviceptr->msock, &readfds);
745 if (serviceptr->msock > highest) {
746 highest = serviceptr->msock;
748 if ((select(highest + 1, &readfds, NULL, NULL, &tv) < 0) && (errno == EBADF)) {
749 // Gotcha! server socket dead? commit suicide!
750 syslog(LOG_ERR, "sysdep: found bad FD: %d and its a server socket! Shutting Down!", serviceptr->msock);
751 server_shutting_down = 1;
759 // select() can wake up on any of the following conditions:
760 // 1. A new client connection on a master socket
761 // 2. Received data on a client socket
763 // That's why we are blocking on select() and not accept().
764 void *worker_thread(void *blah) {
767 CitContext *bind_me = NULL;
772 struct ServiceFunctionHook *serviceptr;
773 int ssock; // Descriptor for client socket
774 CitContext *con = NULL; // Temporary context pointer
777 pthread_mutex_lock(&ThreadCountMutex);
779 pthread_mutex_unlock(&ThreadCountMutex);
781 while (!server_shutting_down) {
783 // make doubly sure we're not holding any stale db handles which might cause a deadlock
785 do_select: force_purge = 0;
786 bind_me = NULL; // Which session shall we handle?
788 // Initialize the fdset
792 // First, add the various master sockets to the fdset.
793 for (serviceptr = ServiceHookTable; serviceptr != NULL; serviceptr = serviceptr->next ) {
794 FD_SET(serviceptr->msock, &readfds);
795 if (serviceptr->msock > highest) {
796 highest = serviceptr->msock;
800 // Next, add all of the client sockets.
801 begin_critical_section(S_SESSION_TABLE);
802 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
803 if ((ptr->state == CON_SYS) && (ptr->client_socket == 0))
806 // Don't select on dead sessions, only truly idle ones
807 if ( (ptr->state == CON_IDLE)
808 && (ptr->kill_me == 0)
809 && (ptr->client_socket > 0)
811 FD_SET(ptr->client_socket, &readfds);
812 if (ptr->client_socket > highest)
813 highest = ptr->client_socket;
815 if ((bind_me == NULL) && (ptr->state == CON_READY)) {
817 ptr->state = CON_EXECUTING;
820 if ((bind_me == NULL) && (ptr->state == CON_GREETING)) {
822 ptr->state = CON_STARTING;
826 end_critical_section(S_SESSION_TABLE);
832 // If we got this far, it means that there are no sessions
833 // which a previous thread marked for attention, so we go
834 // ahead and get ready to select().
836 if (!server_shutting_down) {
837 tv.tv_sec = 1; // wake up every second if no input
839 retval = select(highest + 1, &readfds, NULL, NULL, &tv);
846 // Now figure out who made this select() unblock.
847 // First, check for an error or exit condition.
849 if (errno == EBADF) {
850 syslog(LOG_ERR, "sysdep: select() failed: %m");
854 if (errno != EINTR) {
855 syslog(LOG_ERR, "sysdep: exiting: %m");
856 server_shutting_down = 1;
859 if (server_shutting_down) {
866 else if (retval == 0) {
867 if (server_shutting_down) {
873 // Next, check to see if it's a new client connecting on a master socket.
875 else if ((retval > 0) && (!server_shutting_down)) for (serviceptr = ServiceHookTable; serviceptr != NULL; serviceptr = serviceptr->next) {
877 if (FD_ISSET(serviceptr->msock, &readfds)) {
878 ssock = accept(serviceptr->msock, NULL, 0);
880 syslog(LOG_DEBUG, "sysdep: new client socket %d", ssock);
882 // The master socket is non-blocking but the client
883 // sockets need to be blocking, otherwise certain
884 // operations barf on FreeBSD. Not a fatal error.
885 if (fcntl(ssock, F_SETFL, 0) < 0) {
886 syslog(LOG_ERR, "sysdep: Can't set socket to blocking: %m");
889 // New context will be created already
890 // set up in the CON_EXECUTING state.
891 con = CreateNewContext();
893 // Assign our new socket number to it.
894 con->tcp_port = serviceptr->tcp_port;
895 con->client_socket = ssock;
896 con->h_command_function = serviceptr->h_command_function;
897 con->h_async_function = serviceptr->h_async_function;
898 con->h_greeting_function = serviceptr->h_greeting_function;
899 con->ServiceName = serviceptr->ServiceName;
901 // Connections on a local client are always from the same host
902 if (serviceptr->sockpath != NULL) {
903 con->is_local_client = 1;
906 // Set the SO_REUSEADDR socket option
908 setsockopt(ssock, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
909 con->state = CON_GREETING;
917 // It must be a client socket. Find a context that has data
918 // waiting on its socket *and* is in the CON_IDLE state. Any
919 // active sockets other than our chosen one are marked as
920 // CON_READY so the next thread that comes around can just bind
921 // to one without having to select() again.
922 begin_critical_section(S_SESSION_TABLE);
923 for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
924 int checkfd = ptr->client_socket;
925 if ((checkfd != -1) && (ptr->state == CON_IDLE)){
926 if (FD_ISSET(checkfd, &readfds)) {
927 ptr->input_waiting = 1;
929 bind_me = ptr; // I choose you!
930 bind_me->state = CON_EXECUTING;
933 ptr->state = CON_READY;
936 else if ((ptr->is_async) && (ptr->async_waiting) && (ptr->h_async_function)) {
938 bind_me = ptr; // I choose you!
939 bind_me->state = CON_EXECUTING;
942 ptr->state = CON_READY;
947 end_critical_section(S_SESSION_TABLE);
950 // We're bound to a session
951 pthread_mutex_lock(&ThreadCountMutex);
953 pthread_mutex_unlock(&ThreadCountMutex);
955 if (bind_me != NULL) {
956 become_session(bind_me);
958 if (bind_me->state == CON_STARTING) {
959 bind_me->state = CON_EXECUTING;
960 begin_session(bind_me);
961 bind_me->h_greeting_function();
963 // If the client has sent a command, execute it.
964 if (CC->input_waiting) {
965 CC->h_command_function();
967 while (HaveMoreLinesWaiting(CC))
968 CC->h_command_function();
970 CC->input_waiting = 0;
973 // If there are asynchronous messages waiting and the client supports it, do those now
974 if ((CC->is_async) && (CC->async_waiting) && (CC->h_async_function != NULL)) {
975 CC->h_async_function();
976 CC->async_waiting = 0;
979 force_purge = CC->kill_me;
980 become_session(NULL);
981 bind_me->state = CON_IDLE;
984 dead_session_purge(force_purge);
987 pthread_mutex_lock(&ThreadCountMutex);
989 if ( (active_workers + CtdlGetConfigInt("c_min_workers") < num_workers)
990 && (num_workers > CtdlGetConfigInt("c_min_workers"))
993 pthread_mutex_unlock(&ThreadCountMutex);
996 pthread_mutex_unlock(&ThreadCountMutex);
999 // If control reaches this point, the server is shutting down
1000 pthread_mutex_lock(&ThreadCountMutex);
1002 pthread_mutex_unlock(&ThreadCountMutex);
1008 // Translate text facility name to syslog.h defined value.
1009 int SyslogFacility(char *name) {
1016 { LOG_KERN, "kern" },
1017 { LOG_USER, "user" },
1018 { LOG_MAIL, "mail" },
1019 { LOG_DAEMON, "daemon" },
1020 { LOG_AUTH, "auth" },
1021 { LOG_SYSLOG, "syslog" },
1023 { LOG_NEWS, "news" },
1024 { LOG_UUCP, "uucp" },
1025 { LOG_LOCAL0, "local0" },
1026 { LOG_LOCAL1, "local1" },
1027 { LOG_LOCAL2, "local2" },
1028 { LOG_LOCAL3, "local3" },
1029 { LOG_LOCAL4, "local4" },
1030 { LOG_LOCAL5, "local5" },
1031 { LOG_LOCAL6, "local6" },
1032 { LOG_LOCAL7, "local7" },
1035 for(i = 0; facTbl[i].name != NULL; i++) {
1036 if(!strcasecmp(name, facTbl[i].name))
1037 return facTbl[i].facility;