Project

General

Profile

100-spawn-fcgi_new_opt_directory.patch

add -d option to spawn-fcgi - raphaelh, 2008-12-15 16:54

View differences:

lighttpd-1.4.20/src/spawn-fcgi.c 2008-09-30 10:53:41.000000000 +0200
37 37
#endif
38 38

  
39 39
#ifdef HAVE_SYS_UN_H
40
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) {
40
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) {
41 41
	int fcgi_fd;
42 42
	int socket_type, status, rc = 0;
43 43
	struct timeval tv = { 0, 100 * 1000 };
......
184 184
					strcat(b, appPath);
185 185

  
186 186
					/* exec the cgi */
187
					if(fcgi_dir)
188
					{
189
						if(chdir(fcgi_dir) != 0)
190
						{
191
							exit(errno);
192
						}
193
					}
187 194
					execl("/bin/sh", "sh", "-c", b, (char *)NULL);
188 195
				}
189 196

  
......
273 280
"\n" \
274 281
"Options:\n" \
275 282
" -f <fcgiapp> filename of the fcgi-application\n" \
283
" -d <dir>     chdir to directory before spawning\n" \
276 284
" -a <addr>    bind to ip address\n" \
277 285
" -p <port>    bind to tcp-port\n" \
278 286
" -s <path>    bind to unix-domain socket\n" \
......
292 300

  
293 301

  
294 302
int main(int argc, char **argv) {
295
	char *fcgi_app = NULL, *changeroot = NULL, *username = NULL,
303
	char *fcgi_app = NULL, *fcgi_dir = NULL, *changeroot = NULL, *username = NULL,
296 304
               *groupname = NULL, *unixsocket = NULL, *pid_file = NULL,
297 305
                *addr = NULL;
298 306
	char **fcgi_app_argv = { NULL };
......
306 314

  
307 315
	i_am_root = (getuid() == 0);
308 316

  
309
	while (-1 != (o = getopt(argc, argv, "c:f:g:hna:p:u:vC:F:s:P:"))) {
317
	while(-1 != (o = getopt(argc, argv, "c:f:d:g:hna:p:u:vC:s:P:"))) {
310 318
		switch(o) {
311 319
		case 'f': fcgi_app = optarg; break;
320
		case 'd': fcgi_dir = optarg; break;
312 321
		case 'a': addr = optarg;/* ip addr */ break;
313 322
		case 'p': port = strtol(optarg, NULL, 10);/* port */ break;
314 323
		case 'C': child_count = strtol(optarg, NULL, 10);/*  */ break;
......
471 480
		}
472 481
	}
473 482

  
474
       return fcgi_spawn_connection(fcgi_app, fcgi_app_argv, addr, port, unixsocket, fork_count, child_count, pid_fd, nofork);
483
	return fcgi_spawn_connection(fcgi_app, fcgi_dir, fcgi_app_argv, addr, port, unixsocket, fork_count, child_count, pid_fd, nofork);
475 484
}
476 485
#else
477 486
int main() {