callscgi: Log exec errors.
[ashd.git] / src / callscgi.c
index c5b5499..6adccc5 100644 (file)
@@ -98,13 +98,14 @@ static char *mkanonid(void)
     
     home = getenv("HOME");
     if(home && !access(sprintf3("%s/.ashd/sockets/", home), X_OK))
-       tmpl = sprintf2("%s/.ashd/sockets/scgi-a-XXXXXX");
+       tmpl = sprintf2("%s/.ashd/sockets/scgi-a-XXXXXX", home);
     else
        tmpl = sprintf2("/tmp/scgi-a-%i-XXXXXX", getuid());
     if((fd = mkstemp(tmpl)) < 0) {
        flog(LOG_ERR, "could not create anonymous socket `%s': %s", tmpl, strerror(errno));
        exit(1);
     }
+    close(fd);
     unlink(tmpl);
     return(tmpl);
 }
@@ -193,6 +194,7 @@ static void startlisten(void)
        for(i = 3; i < FD_SETSIZE; i++)
            close(i);
        execvp(*progspec, progspec);
+       flog(LOG_ERR, "callscgi: %s: %s", *progspec, strerror(errno));
        exit(127);
     }
     close(fd);
@@ -216,6 +218,7 @@ static void startnolisten(void)
        dup2(fd, 0);
        close(fd);
        execvp(*progspec, progspec);
+       flog(LOG_ERR, "callscgi: %s: %s", *progspec, strerror(errno));
        exit(127);
     }
 }
@@ -429,7 +432,7 @@ static void mkcgienv(struct hthead *req, struct charbuf *dst)
        bufaddenv(dst, "SERVER_NAME", "%s", h);
     if((h = getheader(req, "X-Ash-Server-Port")) != NULL)
        bufaddenv(dst, "SERVER_PORT", "%s", h);
-    if(((h = getheader(req, "X-Ash-Server-Protocol")) != NULL) && !strcmp(h, "https"))
+    if(((h = getheader(req, "X-Ash-Protocol")) != NULL) && !strcmp(h, "https"))
        bufaddenv(dst, "HTTPS", "on");
     if((h = getheader(req, "X-Ash-Address")) != NULL)
        bufaddenv(dst, "REMOTE_ADDR", "%s", h);
@@ -579,6 +582,11 @@ static void listenloop(struct muth *muth, va_list args)
     }
 }
 
+static void sigexit(int sig)
+{
+    exit(0);
+}
+
 static void usage(FILE *out)
 {
     fprintf(out, "usage: servescgi [-h] [-N RETRIES] [-i ID] [-u UNIX-PATH] [-t [HOST:]TCP-PORT] [PROGRAM [ARGS...]]\n");
@@ -616,6 +624,8 @@ int main(int argc, char **argv)
        exit(1);
     }
     signal(SIGCHLD, SIG_IGN);
+    signal(SIGINT, sigexit);
+    signal(SIGTERM, sigexit);
     mustart(listenloop, 0);
     atexit(killcuraddr);
     ioloop();