]> code.citadel.org Git - citadel.git/blobdiff - webcit/webserver.c
* calculate dirs right
[citadel.git] / webcit / webserver.c
index 78ee06f3153c58a9c6c385b2f95630e36e8fb28c..d67fcc956dc4272fa26d7d7fbe5db4b5077674ab 100644 (file)
@@ -25,11 +25,18 @@ int msock;                      /**< master listening socket */
 int is_https = 0;              /**< Nonzero if I am an HTTPS service */
 int follow_xff = 0;            /**< Follow X-Forwarded-For: header */
 int home_specified = 0; /**< did the user specify a homedir? */
+int time_to_die = 0;            /**< shold we shut down? */
 extern void *context_loop(int);
 extern void *housekeeping_loop(void);
 extern pthread_mutex_t SessionListMutex;
 extern pthread_key_t MyConKey;
 
+
+char ctdl_key_dir[PATH_MAX]=SSL_DIR;
+char file_crpt_file_key[PATH_MAX]="";
+char file_crpt_file_csr[PATH_MAX]="";
+char file_crpt_file_cer[PATH_MAX]="";
+
 char socket_dir[PATH_MAX];      /**< where to talk to our citadel server */
 static const char editor_absolut_dir[PATH_MAX]=EDITORDIR; /**< nailed to what configure gives us. */
 static char static_dir[PATH_MAX]; /**< calculated on startup */
@@ -444,8 +451,8 @@ int client_getln(int sock, char *buf, int bufsiz)
         * Strip any trailing non-printable characters.
         */
        buf[i] = 0;
-       while ((strlen(buf) > 0) && (!isprint(buf[strlen(buf) - 1]))) {
-               buf[strlen(buf) - 1] = 0;
+       while ((i > 0) && (!isprint(buf[i - 1]))) {
+               buf[--i] = 0;
        }
        return (retval);
 }
@@ -455,11 +462,24 @@ int client_getln(int sock, char *buf, int bufsiz)
  * param signum the signal we want to forward
  */
 pid_t current_child;
-void graceful_shutdown(int signum) {
+void graceful_shutdown_watcher(int signum) {
+       lprintf (1, "bye; shutting down watcher.");
        kill(current_child, signum);
        exit(0);
 }
 
+/**
+ * \brief shut us down the regular way.
+ * param signum the signal we want to forward
+ */
+pid_t current_child;
+void graceful_shutdown(int signum) {
+//     kill(current_child, signum);
+       lprintf (1, "bye going down gracefull.");
+       time_to_die = 1;
+       exit(0);
+}
+
 
 /**
  * \brief      Start running as a daemon.  
@@ -499,6 +519,7 @@ void start_daemon(char *pid_file)
        freopen("/dev/null", "r", stdin);
        freopen("/dev/null", "w", stdout);
        freopen("/dev/null", "w", stderr);
+       signal(SIGTERM, graceful_shutdown_watcher);
 
        do {
                current_child = fork();
@@ -511,7 +532,7 @@ void start_daemon(char *pid_file)
        
                else if (current_child == 0) {
                        signal(SIGTERM, graceful_shutdown);
-                       return; /* continue starting citadel. */
+                       return; /* continue starting webcit. */
                }
        
                else {
@@ -608,7 +629,7 @@ int main(int argc, char **argv)
        pthread_attr_t attr;    /**< Thread attributes */
        int a, i;                       /**< General-purpose variables */
        char tracefile[PATH_MAX];
-       char ip_addr[256];
+       char ip_addr[256]="0.0.0.0";
        char dirbuffer[PATH_MAX]="";
        int relh=0;
        int home=0;
@@ -713,6 +734,9 @@ int main(int argc, char **argv)
        if (running_as_daemon) {
                start_daemon(pidfile);
        }
+       else {
+               signal(SIGTERM, graceful_shutdown);
+       }
 
        /** Tell 'em who's in da house */
        lprintf(1, SERVER "\n");
@@ -748,10 +772,24 @@ int main(int argc, char **argv)
                         (dirbuffer[0]!='\0')?"/":"");
        basedir=RUNDIR;
        COMPUTE_DIRECTORY(socket_dir);
-       basedir=DATADIR "/static";
+       basedir=WWWDIR "/static";
        COMPUTE_DIRECTORY(static_dir);
-       basedir=DATADIR "/static.local";
+       basedir=WWWDIR "/static.local";
        COMPUTE_DIRECTORY(static_local_dir);
+
+       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... */
        lprintf(9, "Changing directory to %s\n", socket_dir);
        if (chdir(webcitdir) != 0) {
@@ -787,7 +825,7 @@ int main(int argc, char **argv)
         * exits if it doesn't succeed.
         */
 
-       if (strlen(uds_listen_path) > 0) {
+       if (!IsEmptyStr(uds_listen_path)) {
                lprintf(2, "Attempting to create listener socket at %s...\n", uds_listen_path);
                msock = ig_uds_server(uds_listen_path, LISTEN_QUEUE_LENGTH);
        }
@@ -837,7 +875,6 @@ void worker_entry(void)
 {
        int ssock;
        int i = 0;
-       int time_to_die = 0;
        int fail_this_transaction = 0;
 
        do {
@@ -883,6 +920,7 @@ void worker_entry(void)
 
        } while (!time_to_die);
 
+       lprintf (1, "bye");
        pthread_exit(NULL);
 }