X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fcallscgi.c;h=7e5f51cd13521d2f42a34bfe369a5af2143ce980;hb=9230295ca8434b21ba5d2b2c1d7554d61eab1a71;hp=21db70d058fb37f28d03589250029544ec22775f;hpb=f89ce57a7d216566b30c22f8f8accc9ab0eb5c6c;p=ashd.git diff --git a/src/callscgi.c b/src/callscgi.c index 21db70d..7e5f51c 100644 --- a/src/callscgi.c +++ b/src/callscgi.c @@ -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); } @@ -200,7 +201,7 @@ static void startlisten(void) static void startnolisten(void) { - int i; + int i, fd; if((child = fork()) < 0) { flog(LOG_ERR, "could not fork: %s", strerror(errno)); @@ -209,6 +210,12 @@ static void startnolisten(void) if(child == 0) { for(i = 3; i < FD_SETSIZE; i++) close(i); + if((fd = open("/dev/null", O_RDONLY)) < 0) { + flog(LOG_ERR, "/dev/null: %s", strerror(errno)); + exit(127); + } + dup2(fd, 0); + close(fd); execvp(*progspec, progspec); exit(127); } @@ -262,11 +269,11 @@ retry: } break; } - if(tries++ < nolisten) { - sleep(1); - goto retry; - } if(fd < 0) { + if(tries++ < nolisten) { + sleep(1); + goto retry; + } flog(LOG_ERR, "could not connect to specified TCP address: %s", strerror(errno)); exit(1); } @@ -423,7 +430,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); @@ -436,7 +443,7 @@ static void mkcgienv(struct hthead *req, struct charbuf *dst) if((h = getheader(req, "X-Ash-File")) != NULL) bufaddenv(dst, "SCRIPT_FILENAME", "%s", absolutify(h)); for(i = 0; i < req->noheaders; i++) { - h = sstrdup(req->headers[i][0]); + h = sprintf2("HTTP_%s", req->headers[i][0]); for(p = h; *p; p++) { if(isalnum(*p)) *p = toupper(*p); @@ -573,6 +580,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"); @@ -610,6 +622,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();