Added option to change the directory before spawning (fixes #1847)

git-svn-id: svn://svn.lighttpd.net/spawn-fcgi/trunk@34 4a9f3682-ca7b-49a8-9a55-ba4640e46f83
master
Stefan Bühler 2009-03-26 16:58:22 +00:00
parent e4294c3acf
commit 7897b27d0d
3 changed files with 15 additions and 4 deletions

1
NEWS
View File

@ -8,6 +8,7 @@ NEWS
* Add build date to show-version
* Added options to chown/chmod the socket and to create the socket before chroot() (fixes #1906)
* Updated man page
* Added option to change the directory before spawning (fixes #1847)
- 1.6.0 - 2009-02-28

View File

@ -44,6 +44,9 @@ is recommend to always specify the application (absolute path) and its parameter
.IP
This option is ignored if fcgiapp is given.
.TP 8
.B \-d <path>
Change the current directory before spawning the application.
.TP 8
.B \-a <addr>
IP address to bind to; only used if \-p is given too.
.TP 8

View File

@ -378,6 +378,7 @@ static void show_help () {
"\n" \
"Options:\n" \
" -f <path> filename of the fcgi-application (ignored if <fcgiapp> is given)\n" \
" -d <dir> chdir to directory before spawning\n" \
" -a <addr> bind to ip address\n" \
" -p <port> bind to tcp-port\n" \
" -s <path> bind to unix-domain socket\n" \
@ -404,7 +405,7 @@ static void show_help () {
int main(int argc, char **argv) {
char *fcgi_app = NULL, *changeroot = NULL, *username = NULL,
*groupname = NULL, *unixsocket = NULL, *pid_file = NULL,
*sockusername = NULL, *sockgroupname = NULL,
*sockusername = NULL, *sockgroupname = NULL, *fcgi_dir = NULL,
*addr = NULL;
char **fcgi_app_argv = { NULL };
unsigned short port = 0;
@ -425,9 +426,10 @@ int main(int argc, char **argv) {
i_am_root = (getuid() == 0);
while (-1 != (o = getopt(argc, argv, "c:f:g:?hna:p:u:vC:F:s:P:U:G:M:S"))) {
while (-1 != (o = getopt(argc, argv, "c:d:f:g:?hna:p:u:vC:F:s:P:U:G:M:S"))) {
switch(o) {
case 'f': fcgi_app = optarg; break;
case 'd': fcgi_dir = optarg; break;
case 'a': addr = optarg;/* ip addr */ break;
case 'p': port = strtol(optarg, NULL, 10);/* port */ break;
case 'C': child_count = strtol(optarg, NULL, 10);/* */ break;
@ -543,11 +545,11 @@ int main(int argc, char **argv) {
if (changeroot) {
if (-1 == chroot(changeroot)) {
fprintf(stderr, "spawn-fcgi: chroot failed: %s\n", strerror(errno));
fprintf(stderr, "spawn-fcgi: chroot('%s') failed: %s\n", changeroot, strerror(errno));
return -1;
}
if (-1 == chdir("/")) {
fprintf(stderr, "spawn-fcgi: chdir failed: %s\n", strerror(errno));
fprintf(stderr, "spawn-fcgi: chdir('/') failed: %s\n", strerror(errno));
return -1;
}
}
@ -564,5 +566,10 @@ int main(int argc, char **argv) {
return -1;
}
if (fcgi_dir && -1 == chdir(fcgi_dir)) {
fprintf(stderr, "spawn-fcgi: chdir('%s') failed: %s\n", fcgi_dir, strerror(errno));
return -1;
}
return fcgi_spawn_connection(fcgi_app, fcgi_app_argv, fcgi_fd, fork_count, child_count, pid_fd, nofork);
}