Changeset 2023

Show
Ignore:
Timestamp:
11/12/2007 04:02:47 PM (6 months ago)
Author:
glen
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/lighttpd-1.4.x/src/spawn-fcgi.c

    r2021 r2023  
    3838 
    3939#ifdef HAVE_SYS_UN_H 
    40 int fcgi_spawn_connection(char *appPath, char *addr, unsigned short port, const char *unixsocket, int child_count, int pid_fd, int nofork) { 
     40int fcgi_spawn_connection(char *appPath, char **appArgv, char *addr, unsigned short port, const char *unixsocket, int child_count, int pid_fd, int nofork) { 
    4141        int fcgi_fd; 
    4242        int socket_type, status; 
     
    138138                case 0: { 
    139139                        char cgi_childs[64]; 
    140                         char *b; 
    141140 
    142141                        int i = 0; 
     
    161160 
    162161                        /* fork and replace shell */ 
    163                         b = malloc(strlen("exec ") + strlen(appPath) + 1); 
    164                         strcpy(b, "exec "); 
    165                         strcat(b, appPath); 
    166  
    167                         /* exec the cgi */ 
    168                         execl("/bin/sh", "sh", "-c", b, (char *)NULL); 
     162                        if (appArgv) { 
     163                                execv(appArgv[0], appArgv); 
     164 
     165                        } else { 
     166                                char *b = malloc(strlen("exec ") + strlen(appPath) + 1); 
     167                                strcpy(b, "exec "); 
     168                                strcat(b, appPath); 
     169 
     170                                /* exec the cgi */ 
     171                                execl("/bin/sh", "sh", "-c", b, (char *)NULL); 
     172                        } 
    169173 
    170174                        exit(errno); 
     
    240244 
    241245void show_help () { 
    242         char *b = "spawn-fcgi" "-" PACKAGE_VERSION \ 
    243 " - spawns fastcgi processes\n" \ 
    244 "usage:\n" \ 
     246        char *b = \ 
     247"Usage: spawn-fcgi [options] -- <fcgiapp> [fcgi app arguments]\n" \ 
     248"\n" \ 
     249"spawn-fcgi v" PACKAGE_VERSION " - spawns fastcgi processes\n" \ 
     250"\n" \ 
     251"Options:\n" \ 
    245252" -f <fcgiapp> filename of the fcgi-application\n" \ 
    246253" -a <addr>    bind to ip address\n" \ 
     
    265272               *groupname = NULL, *unixsocket = NULL, *pid_file = NULL, 
    266273                *addr = NULL; 
     274        char **fcgi_app_argv = { NULL }; 
    267275        unsigned short port = 0; 
    268276        int child_count = 5; 
     
    275283        i_am_root = (getuid() == 0); 
    276284 
    277        while(-1 != (o = getopt(argc, argv, "c:f:g:hna:p:u:vC:s:P:"))) { 
     285       while(-1 != (o = getopt(argc, argv, "c:f:g:hna:p:u:vC:s:P:"))) { 
    278286                switch(o) { 
    279287                case 'f': fcgi_app = optarg; break; 
     
    295303        } 
    296304 
    297         if (fcgi_app == NULL || (port == 0 && unixsocket == NULL)) { 
     305        if (optind < argc) { 
     306                fcgi_app_argv = &argv[optind]; 
     307        } 
     308 
     309        if ((fcgi_app == NULL && fcgi_app_argv == NULL) || (port == 0 && unixsocket == NULL)) { 
    298310                show_help(); 
    299311                return -1; 
     
    438450        } 
    439451 
    440        return fcgi_spawn_connection(fcgi_app, addr, port, unixsocket, child_count, pid_fd, nofork); 
     452       return fcgi_spawn_connection(fcgi_app, fcgi_app_argv, addr, port, unixsocket, child_count, pid_fd, nofork); 
    441453} 
    442454#else