Back to index

webcit  8.12-dfsg
Functions | Variables
webserver.c File Reference
#include "webcit.h"
#include "webserver.h"
#include "modules_init.h"

Go to the source code of this file.

Functions

int vsnprintf (char *buf, size_t max, const char *fmt, va_list argp)
void * housekeeping_loop (void)
int webcit_tcp_server (char *ip_addr, int port_number, int queue_len)
int webcit_uds_server (char *sockpath, int queue_len)
void graceful_shutdown_watcher (int signum)
void graceful_shutdown (int signum)
void start_daemon (char *pid_file)
void webcit_calc_dirs_n_files (int relh, const char *basedir, int home, char *webcitdir, char *relhome)
void worker_entry (void)
void drop_root (uid_t UID)
void InitTemplateCache (void)
int main (int argc, char **argv)

Variables

int msock
char static_icon_dir [PATH_MAX]
int is_https = 0
int follow_xff = 0
int DisableGzip = 0
char * default_landing_page = NULL
pthread_mutex_t SessionListMutex
pthread_key_t MyConKey
char socket_dir [PATH_MAX]
char * server_cookie = NULL
int http_port = PORT_NUM
char * ctdlhost = DEFAULT_HOST
char * ctdlport = DEFAULT_PORT
int setup_wizard = 0
char wizard_filename [PATH_MAX]
int running_as_daemon = 0
int dbg_analyze_msg
int dbg_backtrace_template_errors
int DumpTemplateI18NStrings
StrBuf * I18nDump
int LoadTemplates

Function Documentation

void drop_root ( uid_t  UID)

Definition at line 499 of file sysdep.c.

{
       struct passwd pw, *pwp = NULL;

       /*
        * Now that we've bound the sockets, change to the Citadel user id and its
        * corresponding group ids
        */
       if (UID != -1) {
              
#ifdef HAVE_GETPWUID_R
#ifdef SOLARIS_GETPWUID
              pwp = getpwuid_r(UID, &pw, pwbuf, sizeof(pwbuf));
#else /* SOLARIS_GETPWUID */
              getpwuid_r(UID, &pw, pwbuf, sizeof(pwbuf), &pwp);
#endif /* SOLARIS_GETPWUID */
#else /* HAVE_GETPWUID_R */
              pwp = NULL;
#endif /* HAVE_GETPWUID_R */

              if (pwp == NULL)
                     syslog(LOG_CRIT, "WARNING: getpwuid(%d): %s\n"
                            "Group IDs will be incorrect.\n", UID,
                            strerror(errno));
              else {
                     initgroups(pw.pw_name, pw.pw_gid);
                     if (setgid(pw.pw_gid))
                            syslog(LOG_CRIT, "setgid(%ld): %s\n", (long)pw.pw_gid,
                                   strerror(errno));
              }
              syslog(LOG_INFO, "Changing uid to %ld\n", (long)UID);
              if (setuid(UID) != 0) {
                     syslog(LOG_CRIT, "setuid() failed: %s\n", strerror(errno));
              }
#if defined (HAVE_SYS_PRCTL_H) && defined (PR_SET_DUMPABLE)
              prctl(PR_SET_DUMPABLE, 1);
#endif
       }
}

Here is the caller graph for this function:

void graceful_shutdown ( int  signum)

Definition at line 303 of file sysdep.c.

                                   {
       FILE *FD;
       int fd;

       syslog(1, "WebCit is being shut down on signal %d.\n", signum);
       fd = msock;
       msock = -1;
       time_to_die = 1;
       FD=fdopen(fd, "a+");
       fflush (FD);
       fclose (FD);
       close(fd);
       write(ExitPipe[0], HKEY("                              "));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void graceful_shutdown_watcher ( int  signum)

Definition at line 289 of file sysdep.c.

                                           {
       syslog(1, "Watcher thread exiting.\n");
       write(ExitPipe[0], HKEY("                              "));
       kill(current_child, signum);
       if (signum != SIGHUP)
              exit(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* housekeeping_loop ( void  )

Definition at line 130 of file context_loop.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void InitTemplateCache ( void  )

Definition at line 1489 of file subst.c.

{
       int i;
       StrBuf *Key;
       StrBuf *Dir;
       HashList *Templates[2];

       Dir = NewStrBuf();
       Key = NewStrBuf();

       /* Primary Template set... */
       StrBufPrintf(Dir, "%s/t", static_dirs[0]);
       LoadTemplateDir(Dir,
                     TemplateCache, 
                     Key);

       /* User local Template set */
       StrBufPrintf(Dir, "%s/t", static_dirs[1]);
       LoadTemplateDir(Dir,
                     LocalTemplateCache, 
                     Key);
       
       /* Debug Templates, just to be loaded while debugging. */
       
       StrBufPrintf(Dir, "%s/dbg", static_dirs[0]);
       LoadTemplateDir(Dir,
                     TemplateCache, 
                     Key);
       Templates[0] = TemplateCache;
       Templates[1] = LocalTemplateCache;


       if (LoadTemplates == 0) 
              for (i=0; i < 2; i++) {
                     const char *Key;
                     long KLen;
                     HashPos *At;
                     void *vTemplate;

                     At = GetNewHashPos(Templates[i], 0);
                     while (GetNextHashPos(Templates[i], 
                                         At, 
                                         &KLen,
                                         &Key, 
                                         &vTemplate) && 
                            (vTemplate != NULL))
                     {
                            load_template(NULL, (WCTemplate *)vTemplate);
                     }
                     DeleteHashPos(&At);
              }


       FreeStrBuf(&Dir);
       FreeStrBuf(&Key);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 66 of file webserver.c.

{
       uid_t UID = -1;
       size_t basesize = 2;            /* how big should strbufs be on creation? */
       pthread_t SessThread;              /* Thread descriptor */
       pthread_attr_t attr;        /* Thread attributes */
       int a;                      /* General-purpose variable */
       char ip_addr[256]="*";
       int relh=0;
       int home=0;
       char relhome[PATH_MAX]="";
       char webcitdir[PATH_MAX] = DATADIR;
       char *pidfile = NULL;
       char *hdir;
       const char *basedir = NULL;
       char uds_listen_path[PATH_MAX];    /* listen on a unix domain socket? */
       const char *I18nDumpFile = NULL;

       WildFireInitBacktrace(argv[0], 2);

       start_modules();

#ifdef DBG_PRINNT_HOOKS_AT_START
/*     dbg_PrintHash(HandlerHash, nix, NULL);*/
#endif

       /* Ensure that we are linked to the correct version of libcitadel */
       if (libcitadel_version_number() < LIBCITADEL_VERSION_NUMBER) {
              fprintf(stderr, " You are running libcitadel version %d.%02d\n",
                     (libcitadel_version_number() / 100), (libcitadel_version_number() % 100));
              fprintf(stderr, "WebCit was compiled against version %d.%02d\n",
                     (LIBCITADEL_VERSION_NUMBER / 100), (LIBCITADEL_VERSION_NUMBER % 100));
              return(1);
       }

       strcpy(uds_listen_path, "");

       /* Parse command line */
#ifdef HAVE_OPENSSL
       while ((a = getopt(argc, argv, "u:h:i:p:t:T:B:x:g:dD:G:cfsS:Z")) != EOF)
#else
       while ((a = getopt(argc, argv, "u:h:i:p:t:T:B:x:g:dD:G:cfZ")) != EOF)
#endif
              switch (a) {
              case 'u':
                     UID = atol(optarg);
                     break;
              case 'h':
                     hdir = strdup(optarg);
                     relh=hdir[0]!='/';
                     if (!relh) {
                            safestrncpy(webcitdir, hdir, sizeof webcitdir);
                     }
                     else {
                            safestrncpy(relhome, relhome, sizeof relhome);
                     }
                     /* free(hdir); TODO: SHOULD WE DO THIS? */
                     home=1;
                     break;
              case 'd':
                     running_as_daemon = 1;
                     break;
              case 'D':
                     pidfile = strdup(optarg);
                     running_as_daemon = 1;
                     break;
              case 'g':
                     default_landing_page = strdup(optarg);
                     break;
              case 'B': /* Basesize */
                     basesize = atoi(optarg);
                     if (basesize > 2)
                            StartLibCitadel(basesize);
                     break;
              case 'i':
                     safestrncpy(ip_addr, optarg, sizeof ip_addr);
                     break;
              case 'p':
                     http_port = atoi(optarg);
                     if (http_port == 0) {
                            safestrncpy(uds_listen_path, optarg, sizeof uds_listen_path);
                     }
                     break;
              case 't':
                     /* no longer used, but ignored so old scripts don't break */
                     break;
              case 'T':
                     LoadTemplates = atoi(optarg);
                     dbg_analyze_msg = (LoadTemplates && (1<<1)) != 0;
                     dbg_backtrace_template_errors = (LoadTemplates && (1<<2)) != 0;
                     break;
              case 'Z':
                     DisableGzip = 1;
                     break;
              case 'x':
                     /* no longer used, but ignored so old scripts don't break */
                     break;
              case 'f':
                     follow_xff = 1;
                     break;
              case 'c':
                     server_cookie = malloc(256);
                     if (server_cookie != NULL) {
                            safestrncpy(server_cookie,
                                   "Set-cookie: wcserver=",
                                   256);
                            if (gethostname
                                (&server_cookie[strlen(server_cookie)],
                                 200) != 0) {
                                   syslog(2, "gethostname: %s", strerror(errno));
                                   free(server_cookie);
                            }
                     }
                     break;
#ifdef HAVE_OPENSSL
              case 's':
                     is_https = 1;
                     break;
              case 'S':
                     is_https = 1;
                     ssl_cipher_list = strdup(optarg);
                     break;
#endif
              case 'G':
                     DumpTemplateI18NStrings = 1;
                     I18nDump = NewStrBufPlain(HKEY("int templatestrings(void)\n{\n"));
                     I18nDumpFile = optarg;
                     break;
              default:
                     fprintf(stderr, "usage: webcit "
                            "[-i ip_addr] [-p http_port] "
                            "[-c] [-f] "
                            "[-T Templatedebuglevel] "
                            "[-d] [-Z] [-G i18ndumpfile] "
#ifdef HAVE_OPENSSL
                            "[-s] [-S cipher_suites]"
#endif
                            "[remotehost [remoteport]]\n");
                     return 1;
              }

       /* Start the logger */
       openlog("webcit",
              ( running_as_daemon ? (LOG_PID) : (LOG_PID | LOG_PERROR) ),
              LOG_DAEMON
       );

       if (optind < argc) {
              ctdlhost = argv[optind];
              if (++optind < argc)
                     ctdlport = argv[optind];
       }

       /* daemonize, if we were asked to */
       if (!DumpTemplateI18NStrings && running_as_daemon) {
              start_daemon(pidfile);
       }
       else {
              signal(SIGINT, graceful_shutdown);
              signal(SIGHUP, graceful_shutdown);
       }

       webcit_calc_dirs_n_files(relh, basedir, home, webcitdir, relhome);
       LoadIconDir(static_icon_dir);

       /* Tell 'em who's in da house */
       syslog(1, "%s", PACKAGE_STRING);
       syslog(1, "Copyright (C) 1996-2012 by the citadel.org team");
       syslog(1, " ");
       syslog(1, "This program is open source software: you can redistribute it and/or");
       syslog(1, "modify it under the terms of the GNU General Public License, version 3.");
       syslog(1, " ");
       syslog(1, "This program is distributed in the hope that it will be useful,");
       syslog(1, "but WITHOUT ANY WARRANTY; without even the implied warranty of");
       syslog(1, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the");
       syslog(1, "GNU General Public License for more details.");
       syslog(1, " ");

       /* initialize various subsystems */

       initialise_modules();
       initialise2_modules();
       InitTemplateCache();
       if (DumpTemplateI18NStrings) {
              FILE *fd;
              StrBufAppendBufPlain(I18nDump, HKEY("}\n"), 0);
               if (StrLength(I18nDump) < 50) {
                     syslog(1, "*******************************************************************\n");
                     syslog(1, "*   No strings found in templates!  Are you sure they're there?   *\n");
                     syslog(1, "*******************************************************************\n");
                     return -1;
              }
              fd = fopen(I18nDumpFile, "w");
               if (fd == NULL) {
                     syslog(1, "***********************************************\n");
                     syslog(1, "*   unable to open I18N dumpfile [%s]         *\n", I18nDumpFile);
                     syslog(1, "***********************************************\n");
                     return -1;
              }
              fwrite(ChrPtr(I18nDump), 1, StrLength(I18nDump), fd);
              fclose(fd);
              return 0;
       }

       /* Tell libical to return an error instead of aborting if it sees badly formed iCalendar data. */
       icalerror_errors_are_fatal = 0;

       /* Use our own prefix on tzid's generated from system tzdata */
       icaltimezone_set_tzid_prefix("/citadel.org/");

       /*
        * Set up a place to put thread-specific data.
        * We only need a single pointer per thread - it points to the
        * wcsession struct to which the thread is currently bound.
        */
       if (pthread_key_create(&MyConKey, NULL) != 0) {
              syslog(1, "Can't create TSD key: %s", strerror(errno));
       }
       InitialiseSemaphores();

       /*
        * Set up a place to put thread-specific SSL data.
        * We don't stick this in the wcsession struct because SSL starts
        * up before the session is bound, and it gets torn down between
        * transactions.
        */
#ifdef HAVE_OPENSSL
       if (pthread_key_create(&ThreadSSL, NULL) != 0) {
              syslog(1, "Can't create TSD key: %s", strerror(errno));
       }
#endif

       /*
        * Bind the server to our favorite port.
        * There is no need to check for errors, because webcit_tcp_server()
        * exits if it doesn't succeed.
        */

       if (!IsEmptyStr(uds_listen_path)) {
              syslog(2, "Attempting to create listener socket at %s...", uds_listen_path);
              msock = webcit_uds_server(uds_listen_path, LISTEN_QUEUE_LENGTH);
       }
       else {
              syslog(2, "Attempting to bind to port %d...", http_port);
              msock = webcit_tcp_server(ip_addr, http_port, LISTEN_QUEUE_LENGTH);
       }
       if (msock < 0)
       {
              ShutDownWebcit();
              return -msock;
       }

       syslog(2, "Listening on socket %d", msock);
       signal(SIGPIPE, SIG_IGN);

       pthread_mutex_init(&SessionListMutex, NULL);

       /*
        * Start up the housekeeping thread
        */
       pthread_attr_init(&attr);
       pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
       pthread_create(&SessThread, &attr, (void *(*)(void *)) housekeeping_loop, NULL);

       /*
        * If this is an HTTPS server, fire up SSL
        */
#ifdef HAVE_OPENSSL
       if (is_https) {
              init_ssl();
       }
#endif
       drop_root(UID);

       /* Become a worker thread.  More worker threads will be spawned as they are needed. */
       worker_entry();
       ShutDownLibCitadel();
       return 0;
}

Here is the call graph for this function:

void start_daemon ( char *  pid_file)

Definition at line 322 of file sysdep.c.

{
       int status = 0;
       pid_t child = 0;
       FILE *fp;
       int do_restart = 0;

       current_child = 0;

       /* Close stdin/stdout/stderr and replace them with /dev/null.
        * We don't just call close() because we don't want these fd's
        * to be reused for other files.
        */
       chdir("/");

       signal(SIGHUP, SIG_IGN);
       signal(SIGINT, SIG_IGN);
       signal(SIGQUIT, SIG_IGN);

       child = fork();
       if (child != 0) {
              exit(0);
       }

       setsid();
       umask(0);
       freopen("/dev/null", "r", stdin);
       freopen("/dev/null", "w", stdout);
       freopen("/dev/null", "w", stderr);
       signal(SIGTERM, graceful_shutdown_watcher);
       signal(SIGHUP, graceful_shutdown_watcher);

       do {
              current_child = fork();

       
              if (current_child < 0) {
                     perror("fork");
                     ShutDownLibCitadel ();
                     exit(errno);
              }
       
              else if (current_child == 0) {     /* child process */
                     signal(SIGHUP, graceful_shutdown);

                     return; /* continue starting webcit. */
              }
              else { /* watcher process */
                     if (pid_file) {
                            fp = fopen(pid_file, "w");
                            if (fp != NULL) {
                                   fprintf(fp, "%d\n", getpid());
                                   fclose(fp);
                            }
                     }
                     waitpid(current_child, &status, 0);
              }

              do_restart = 0;

              /* Did the main process exit with an actual exit code? */
              if (WIFEXITED(status)) {

                     /* Exit code 0 means the watcher should exit */
                     if (WEXITSTATUS(status) == 0) {
                            do_restart = 0;
                     }

                     /* Exit code 101-109 means the watcher should exit */
                     else if ( (WEXITSTATUS(status) >= 101) && (WEXITSTATUS(status) <= 109) ) {
                            do_restart = 0;
                     }

                     /* Any other exit code means we should restart. */
                     else {
                            do_restart = 1;
                     }
              }

              /* Any other type of termination (signals, etc.) should also restart. */
              else {
                     do_restart = 1;
              }

       } while (do_restart);

       if (pid_file) {
              unlink(pid_file);
       }
       ShutDownLibCitadel ();
       exit(WEXITSTATUS(status));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int vsnprintf ( char *  buf,
size_t  max,
const char *  fmt,
va_list  argp 
)

Here is the caller graph for this function:

void webcit_calc_dirs_n_files ( int  relh,
const char *  basedir,
int  home,
char *  webcitdir,
char *  relhome 
)

Definition at line 452 of file sysdep.c.

{
       char dirbuffer[PATH_MAX]="";
       /* calculate all our path on a central place */
    /* where to keep our config */
       
#define COMPUTE_DIRECTORY(SUBDIR) memcpy(dirbuffer,SUBDIR, sizeof dirbuffer);\
       snprintf(SUBDIR,sizeof SUBDIR,  "%s%s%s%s%s%s%s", \
                      (home&!relh)?webcitdir:basedir, \
             ((basedir!=webcitdir)&(home&!relh))?basedir:"/", \
             ((basedir!=webcitdir)&(home&!relh))?"/":"", \
                      relhome, \
             (relhome[0]!='\0')?"/":"",\
                      dirbuffer,\
                      (dirbuffer[0]!='\0')?"/":"");
       basedir=RUNDIR;
       COMPUTE_DIRECTORY(socket_dir);
       basedir=WWWDIR "/static";
       COMPUTE_DIRECTORY(static_dir);
       basedir=WWWDIR "/static/icons";
       COMPUTE_DIRECTORY(static_icon_dir);
       basedir=WWWDIR "/static.local";
       COMPUTE_DIRECTORY(static_local_dir);
       StripSlashes(static_dir, 1);
       StripSlashes(static_icon_dir, 1);
       StripSlashes(static_local_dir, 1);

       snprintf(file_crpt_file_key,
               sizeof file_crpt_file_key, 
               "%s/citadel.key",
               ctdl_key_dir);
       snprintf(file_crpt_file_csr,
               sizeof file_crpt_file_csr, 
               "%s/citadel.csr",
               ctdl_key_dir);
       snprintf(file_crpt_file_cer,
               sizeof file_crpt_file_cer, 
               "%s/citadel.cer",
               ctdl_key_dir);

       /* we should go somewhere we can leave our coredump, if enabled... */
       syslog(9, "Changing directory to %s\n", socket_dir);
       if (chdir(webcitdir) != 0) {
              perror("chdir");
       }
}

Here is the caller graph for this function:

int webcit_tcp_server ( char *  ip_addr,
int  port_number,
int  queue_len 
)

Definition at line 515 of file tcp_sockets.c.

{
       struct protoent *p;
       struct sockaddr_in6 sin6;
       struct sockaddr_in sin4;
       int s, i, b;
       int ip_version = 6;

       memset(&sin6, 0, sizeof(sin6));
       memset(&sin4, 0, sizeof(sin4));
       sin6.sin6_family = AF_INET6;
       sin4.sin_family = AF_INET;

       if (   (ip_addr == NULL)                                              /* any IPv6 */
              || (IsEmptyStr(ip_addr))
              || (!strcmp(ip_addr, "*"))
       ) {
              ip_version = 6;
              sin6.sin6_addr = in6addr_any;
       }
       else if (!strcmp(ip_addr, "0.0.0.0"))                                        /* any IPv4 */
       {
              ip_version = 4;
              sin4.sin_addr.s_addr = INADDR_ANY;
       }
       else if ((strchr(ip_addr, '.')) && (!strchr(ip_addr, ':')))                  /* specific IPv4 */
       {
              ip_version = 4;
              if (inet_pton(AF_INET, ip_addr, &sin4.sin_addr) <= 0) {
                     syslog(1, "Error binding to [%s] : %s\n", ip_addr, strerror(errno));
                     return (-WC_EXIT_BIND);
              }
       }
       else                                                                  /* specific IPv6 */
       {
              ip_version = 6;
              if (inet_pton(AF_INET6, ip_addr, &sin6.sin6_addr) <= 0) {
                     syslog(1, "Error binding to [%s] : %s\n", ip_addr, strerror(errno));
                     return (-WC_EXIT_BIND);
              }
       }

       if (port_number == 0) {
              syslog(1, "Cannot start: no port number specified.\n");
              return (-WC_EXIT_BIND);
       }
       sin6.sin6_port = htons((u_short) port_number);
       sin4.sin_port = htons((u_short) port_number);

       p = getprotobyname("tcp");

       s = socket( ((ip_version == 6) ? PF_INET6 : PF_INET), SOCK_STREAM, (p->p_proto));
       if (s < 0) {
              syslog(1, "Can't create a listening socket: %s\n", strerror(errno));
              return (-WC_EXIT_BIND);
       }
       /* Set some socket options that make sense. */
       i = 1;
       setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));

       if (ip_version == 6) {
              b = bind(s, (struct sockaddr *) &sin6, sizeof(sin6));
       }
       else {
              b = bind(s, (struct sockaddr *) &sin4, sizeof(sin4));
       }

       if (b < 0) {
              syslog(1, "Can't bind: %s\n", strerror(errno));
              close(s);
              return (-WC_EXIT_BIND);
       }

       if (listen(s, queue_len) < 0) {
              syslog(1, "Can't listen: %s\n", strerror(errno));
              close(s);
              return (-WC_EXIT_BIND);
       }
       return (s);
}

Here is the caller graph for this function:

int webcit_uds_server ( char *  sockpath,
int  queue_len 
)

Definition at line 602 of file tcp_sockets.c.

{
       struct sockaddr_un addr;
       int s;
       int i;
       int actual_queue_len;

       actual_queue_len = queue_len;
       if (actual_queue_len < 5) actual_queue_len = 5;

       i = unlink(sockpath);
       if ((i != 0) && (errno != ENOENT)) {
              syslog(1, "webcit: can't unlink %s: %s\n",
                     sockpath, strerror(errno));
              return (-WC_EXIT_BIND);
       }

       memset(&addr, 0, sizeof(addr));
       addr.sun_family = AF_UNIX;
       safestrncpy(addr.sun_path, sockpath, sizeof addr.sun_path);

       s = socket(AF_UNIX, SOCK_STREAM, 0);
       if (s < 0) {
              syslog(1, "webcit: Can't create a unix domain socket: %s\n", strerror(errno));
              return (-WC_EXIT_BIND);
       }

       if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
              syslog(1, "webcit: Can't bind: %s\n", strerror(errno));
              close(s);
              return (-WC_EXIT_BIND);
       }

       if (listen(s, actual_queue_len) < 0) {
              syslog(1, "webcit: Can't listen: %s\n", strerror(errno));
              close(s);
              return (-WC_EXIT_BIND);
       }

       chmod(sockpath, 0777);
       return(s);
}

Here is the caller graph for this function:

void worker_entry ( void  )

Definition at line 152 of file sysdep.c.

{
       int ssock;
       int i = 0;
       int fail_this_transaction = 0;
       ParsedHttpHdrs Hdr;

       memset(&Hdr, 0, sizeof(ParsedHttpHdrs));
       Hdr.HR.eReqType = eGET;
       http_new_modules(&Hdr);     

       do {
              /* Each worker thread blocks on accept() while waiting for something to do. */
              fail_this_transaction = 0;
              ssock = -1; 
              errno = EAGAIN;
              do {
                     fd_set wset;
                     --num_threads_executing;
                        FD_ZERO(&wset);
                        FD_SET(msock, &wset);
                        FD_SET(ExitPipe[1], &wset);

                        select(msock + 1, NULL, &wset, NULL, NULL);
                     if (time_to_die)
                            break;

                     ssock = accept(msock, NULL, 0);
                     ++num_threads_executing;
                     if (ssock < 0) fail_this_transaction = 1;
              } while ((msock > 0) && (ssock < 0)  && (time_to_die == 0));

              if ((msock == -1)||(time_to_die))
              {/* ok, we're going down. */
                     int shutdown = 0;

                     /* The first thread to get here will have to do the cleanup.
                      * Make sure it's really just one.
                      */
                     begin_critical_section(S_SHUTDOWN);
                     if (msock == -1)
                     {
                            msock = -2;
                            shutdown = 1;
                     }
                     end_critical_section(S_SHUTDOWN);
                     if (shutdown == 1)
                     {/* we're the one to cleanup the mess. */
                            http_destroy_modules(&Hdr);
                            syslog(2, "I'm master shutdown: tagging sessions to be killed.\n");
                            shutdown_sessions();
                            syslog(2, "master shutdown: waiting for others\n");
                            sleeeeeeeeeep(1); /* wait so some others might finish... */
                            syslog(2, "master shutdown: cleaning up sessions\n");
                            do_housekeeping();
                            syslog(2, "master shutdown: cleaning up libical\n");

                            ShutDownWebcit();

                            syslog(2, "master shutdown exiting.\n");                       
                            exit(0);
                     }
                     break;
              }
              if (ssock < 0 ) continue;

              check_thread_pool_size();

              /* Now do something. */
              if (msock < 0) {
                     if (ssock > 0) close (ssock);
                     syslog(2, "in between.");
                     pthread_exit(NULL);
              } else {
                     /* Got it? do some real work! */
                     /* Set the SO_REUSEADDR socket option */
                     i = 1;
                     setsockopt(ssock, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));

                     /* If we are an HTTPS server, go crypto now. */
#ifdef HAVE_OPENSSL
                     if (is_https) {
                            if (starttls(ssock) != 0) {
                                   fail_this_transaction = 1;
                                   close(ssock);
                            }
                     }
                     else 
#endif
                     {
                            int fdflags; 
                            fdflags = fcntl(ssock, F_GETFL);
                            if (fdflags < 0)
                                   syslog(1, "unable to get server socket flags! %s \n",
                                          strerror(errno));
                            fdflags = fdflags | O_NONBLOCK;
                            if (fcntl(ssock, F_SETFL, fdflags) < 0)
                                   syslog(1, "unable to set server socket nonblocking flags! %s \n",
                                          strerror(errno));
                     }

                     if (fail_this_transaction == 0) {
                            Hdr.http_sock = ssock;

                            /* Perform an HTTP transaction... */
                            context_loop(&Hdr);

                            /* Shut down SSL/TLS if required... */
#ifdef HAVE_OPENSSL
                            if (is_https) {
                                   endtls();
                            }
#endif

                            /* ...and close the socket. */
                            if (Hdr.http_sock > 0) {
                                   lingering_close(ssock);
                            }
                            http_detach_modules(&Hdr);

                     }

              }

       } while (!time_to_die);

       http_destroy_modules(&Hdr);
       syslog(1, "Thread exiting.\n");
       pthread_exit(NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 43 of file webserver.c.

Definition at line 44 of file webserver.c.

Definition at line 24 of file messages.c.

Definition at line 32 of file subst.c.

char* default_landing_page = NULL

Definition at line 26 of file webserver.c.

int DisableGzip = 0

Definition at line 25 of file webserver.c.

Definition at line 30 of file subst.c.

int follow_xff = 0

Definition at line 24 of file webserver.c.

Definition at line 42 of file webserver.c.

StrBuf* I18nDump

Definition at line 34 of file subst.c.

int is_https = 0

Definition at line 23 of file webserver.c.

Definition at line 31 of file subst.c.

int msock

Definition at line 74 of file sysdep.c.

pthread_key_t MyConKey

Definition at line 27 of file context_loop.c.

Definition at line 47 of file webserver.c.

char* server_cookie = NULL

Definition at line 41 of file webserver.c.

pthread_mutex_t SessionListMutex

Definition at line 23 of file context_loop.c.

int setup_wizard = 0

Definition at line 45 of file webserver.c.

char socket_dir[PATH_MAX]

Definition at line 40 of file webserver.c.

char static_icon_dir[PATH_MAX]

Definition at line 89 of file sysdep.c.

char wizard_filename[PATH_MAX]

Definition at line 46 of file webserver.c.