- use execv() directly to fcgi app if used as argument. resolves #1428

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2023 152afb58-edef-0310-8abb-c4023f1b3aa9
This commit is contained in:
Elan Ruusamäe 2007-11-12 16:02:47 +00:00
parent 68ebed3753
commit b0f37b9c50
1 changed files with 25 additions and 13 deletions

View File

@ -37,7 +37,7 @@ typedef int socklen_t;
#endif
#ifdef HAVE_SYS_UN_H
int fcgi_spawn_connection(char *appPath, char *addr, unsigned short port, const char *unixsocket, int child_count, int pid_fd, int nofork) {
int fcgi_spawn_connection(char *appPath, char **appArgv, char *addr, unsigned short port, const char *unixsocket, int child_count, int pid_fd, int nofork) {
int fcgi_fd;
int socket_type, status;
struct timeval tv = { 0, 100 * 1000 };
@ -137,7 +137,6 @@ int fcgi_spawn_connection(char *appPath, char *addr, unsigned short port, const
switch (child) {
case 0: {
char cgi_childs[64];
char *b;
int i = 0;
@ -160,12 +159,17 @@ int fcgi_spawn_connection(char *appPath, char *addr, unsigned short port, const
putenv(cgi_childs);
/* fork and replace shell */
b = malloc(strlen("exec ") + strlen(appPath) + 1);
strcpy(b, "exec ");
strcat(b, appPath);
if (appArgv) {
execv(appArgv[0], appArgv);
/* exec the cgi */
execl("/bin/sh", "sh", "-c", b, (char *)NULL);
} else {
char *b = malloc(strlen("exec ") + strlen(appPath) + 1);
strcpy(b, "exec ");
strcat(b, appPath);
/* exec the cgi */
execl("/bin/sh", "sh", "-c", b, (char *)NULL);
}
exit(errno);
@ -239,9 +243,12 @@ void show_version () {
}
void show_help () {
char *b = "spawn-fcgi" "-" PACKAGE_VERSION \
" - spawns fastcgi processes\n" \
"usage:\n" \
char *b = \
"Usage: spawn-fcgi [options] -- <fcgiapp> [fcgi app arguments]\n" \
"\n" \
"spawn-fcgi v" PACKAGE_VERSION " - spawns fastcgi processes\n" \
"\n" \
"Options:\n" \
" -f <fcgiapp> filename of the fcgi-application\n" \
" -a <addr> bind to ip address\n" \
" -p <port> bind to tcp-port\n" \
@ -264,6 +271,7 @@ int main(int argc, char **argv) {
char *fcgi_app = NULL, *changeroot = NULL, *username = NULL,
*groupname = NULL, *unixsocket = NULL, *pid_file = NULL,
*addr = NULL;
char **fcgi_app_argv = { NULL };
unsigned short port = 0;
int child_count = 5;
int i_am_root, o;
@ -274,7 +282,7 @@ int main(int argc, char **argv) {
i_am_root = (getuid() == 0);
while(-1 != (o = getopt(argc, argv, "c:f:g:hna:p:u:vC:s:P:"))) {
while(-1 != (o = getopt(argc, argv, "c:f:g:hna:p:u:vC:s:P:"))) {
switch(o) {
case 'f': fcgi_app = optarg; break;
case 'a': addr = optarg;/* ip addr */ break;
@ -294,7 +302,11 @@ int main(int argc, char **argv) {
}
}
if (fcgi_app == NULL || (port == 0 && unixsocket == NULL)) {
if (optind < argc) {
fcgi_app_argv = &argv[optind];
}
if ((fcgi_app == NULL && fcgi_app_argv == NULL) || (port == 0 && unixsocket == NULL)) {
show_help();
return -1;
}
@ -437,7 +449,7 @@ int main(int argc, char **argv) {
}
}
return fcgi_spawn_connection(fcgi_app, addr, port, unixsocket, child_count, pid_fd, nofork);
return fcgi_spawn_connection(fcgi_app, fcgi_app_argv, addr, port, unixsocket, child_count, pid_fd, nofork);
}
#else
int main() {