Ticket #1428: lighttpd-spawn-fcgi-argv.patch

File lighttpd-spawn-fcgi-argv.patch, 2.4 kB (added by glen, 6 months ago)

accept -f <arg> as last argument, fallbacks to old -f method

  • src/spawn-fcgi.c

    old new  
    3737#endif 
    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; 
    4343        struct timeval tv = { 0, 100 * 1000 }; 
     
    137137                switch (child) { 
    138138                case 0: { 
    139139                        char cgi_childs[64]; 
    140                         char *b; 
    141140 
    142141                        int i = 0; 
    143142 
     
    160159                        putenv(cgi_childs); 
    161160 
    162161                        /* fork and replace shell */ 
    163                         b = malloc(strlen("exec ") + strlen(appPath) + 1); 
    164                         strcpy(b, "exec "); 
    165                         strcat(b, appPath); 
     162                        if (appArgv) { 
     163                                execv(appArgv[0], appArgv); 
    166164 
    167                         /* exec the cgi */ 
    168                         execl("/bin/sh", "sh", "-c", b, (char *)NULL); 
     165                        } else { 
     166                                char *b = malloc(strlen("exec ") + strlen(appPath) + 1); 
     167                                strcpy(b, "exec "); 
     168                                strcat(b, appPath); 
    169169 
     170                                /* exec the cgi */ 
     171                                execl("/bin/sh", "sh", "-c", b, (char *)NULL); 
     172                        } 
     173 
    170174                        exit(errno); 
    171175 
    172176                        break; 
     
    264268        char *fcgi_app = NULL, *changeroot = NULL, *username = NULL, 
    265269               *groupname = NULL, *unixsocket = NULL, *pid_file = NULL, 
    266270                *addr = NULL; 
     271        char **fcgi_app_argv = { NULL }; 
    267272        unsigned short port = 0; 
    268273        int child_count = 5; 
    269274        int i_am_root, o; 
     
    274279 
    275280        i_am_root = (getuid() == 0); 
    276281 
    277        while(-1 != (o = getopt(argc, argv, "c:f:g:hna:p:u:vC:s:P:"))) { 
     282       while(-1 != (o = getopt(argc, argv, "c:f:g:hna:p:u:vC:s:P:"))) { 
    278283                switch(o) { 
    279284                case 'f': fcgi_app = optarg; break; 
    280285               case 'a': addr = optarg;/* ip addr */ break; 
     
    294299                } 
    295300        } 
    296301 
    297         if (fcgi_app == NULL || (port == 0 && unixsocket == NULL)) { 
     302        if (optind < argc) { 
     303                fcgi_app_argv = &argv[optind]; 
     304        } 
     305 
     306        if ((fcgi_app == NULL && fcgi_app_argv == NULL) || (port == 0 && unixsocket == NULL)) { 
    298307                show_help(); 
    299308                return -1; 
    300309        } 
     
    437446                } 
    438447        } 
    439448 
    440        return fcgi_spawn_connection(fcgi_app, addr, port, unixsocket, child_count, pid_fd, nofork); 
     449       return fcgi_spawn_connection(fcgi_app, fcgi_app_argv, addr, port, unixsocket, child_count, pid_fd, nofork); 
    441450} 
    442451#else 
    443452int main() {