[package] add directory option to spawn-fcgi (#4355), thanks Raphael
[openwrt/svn-archive/archive.git] / net / lighttpd / patches / 100-spawn-fcgi_new_opt_directory.patch
1 --- lighttpd-1.4.20.orig/src/spawn-fcgi.c 2008-09-30 10:53:27.000000000 +0200
2 +++ lighttpd-1.4.20/src/spawn-fcgi.c 2008-09-30 10:53:41.000000000 +0200
3 @@ -37,7 +37,7 @@ typedef int socklen_t;
4 #endif
5
6 #ifdef HAVE_SYS_UN_H
7 -int fcgi_spawn_connection(char *appPath, char **appArgv, char *addr, unsigned short port, const char *unixsocket, int fork_count, int child_count, int pid_fd, int nofork) {
8 +int fcgi_spawn_connection(char *appPath, const char *fcgi_dir, char **appArgv, char *addr, unsigned short port, const char *unixsocket, int fork_count, int child_count, int pid_fd, int nofork) {
9 int fcgi_fd;
10 int socket_type, status, rc = 0;
11 struct timeval tv = { 0, 100 * 1000 };
12 @@ -184,6 +184,13 @@ int fcgi_spawn_connection(char *appPath,
13 strcat(b, appPath);
14
15 /* exec the cgi */
16 + if(fcgi_dir)
17 + {
18 + if(chdir(fcgi_dir) != 0)
19 + {
20 + exit(errno);
21 + }
22 + }
23 execl("/bin/sh", "sh", "-c", b, (char *)NULL);
24 }
25
26 @@ -273,6 +280,7 @@ void show_help () {
27 "\n" \
28 "Options:\n" \
29 " -f <fcgiapp> filename of the fcgi-application\n" \
30 +" -d <dir> chdir to directory before spawning\n" \
31 " -a <addr> bind to ip address\n" \
32 " -p <port> bind to tcp-port\n" \
33 " -s <path> bind to unix-domain socket\n" \
34 @@ -292,7 +300,7 @@ void show_help () {
35
36
37 int main(int argc, char **argv) {
38 - char *fcgi_app = NULL, *changeroot = NULL, *username = NULL,
39 + char *fcgi_app = NULL, *fcgi_dir = NULL, *changeroot = NULL, *username = NULL,
40 *groupname = NULL, *unixsocket = NULL, *pid_file = NULL,
41 *addr = NULL;
42 char **fcgi_app_argv = { NULL };
43 @@ -306,9 +314,10 @@ int main(int argc, char **argv) {
44
45 i_am_root = (getuid() == 0);
46
47 - while (-1 != (o = getopt(argc, argv, "c:f:g:hna:p:u:vC:F:s:P:"))) {
48 + while(-1 != (o = getopt(argc, argv, "c:f:d:g:hna:p:u:vC:s:P:"))) {
49 switch(o) {
50 case 'f': fcgi_app = optarg; break;
51 + case 'd': fcgi_dir = optarg; break;
52 case 'a': addr = optarg;/* ip addr */ break;
53 case 'p': port = strtol(optarg, NULL, 10);/* port */ break;
54 case 'C': child_count = strtol(optarg, NULL, 10);/* */ break;
55 @@ -471,7 +480,7 @@ int main(int argc, char **argv) {
56 }
57 }
58
59 - return fcgi_spawn_connection(fcgi_app, fcgi_app_argv, addr, port, unixsocket, fork_count, child_count, pid_fd, nofork);
60 + return fcgi_spawn_connection(fcgi_app, fcgi_dir, fcgi_app_argv, addr, port, unixsocket, fork_count, child_count, pid_fd, nofork);
61 }
62 #else
63 int main() {