aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Bühler <stbuehler@web.de>2009-03-26 16:58:22 +0000
committerStefan Bühler <stbuehler@web.de>2009-03-26 16:58:22 +0000
commit7897b27d0d9c1abda2e6d16bd0090678c03f1302 (patch)
tree181edab21cef293685a8b660e7812330630de0aa
parente4294c3acf76299d58740e59008c874d79fc5d15 (diff)
downloadspawn-fcgi-7897b27d0d9c1abda2e6d16bd0090678c03f1302.tar.gz
spawn-fcgi-7897b27d0d9c1abda2e6d16bd0090678c03f1302.zip
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
-rw-r--r--NEWS1
-rw-r--r--spawn-fcgi.13
-rw-r--r--src/spawn-fcgi.c15
3 files changed, 15 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index 5b3b193..5dac069 100644
--- a/NEWS
+++ b/NEWS
@@ -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
diff --git a/spawn-fcgi.1 b/spawn-fcgi.1
index 8f72e54..6a123da 100644
--- a/spawn-fcgi.1
+++ b/spawn-fcgi.1
@@ -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
diff --git a/src/spawn-fcgi.c b/src/spawn-fcgi.c
index 45e9834..c4ccd7e 100644
--- a/src/spawn-fcgi.c
+++ b/src/spawn-fcgi.c
@@ -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);
}