aboutsummaryrefslogtreecommitdiff
path: root/fcgi-cgi.c
diff options
context:
space:
mode:
authorStefan Bühler <stbuehler@web.de>2009-11-11 16:05:46 +0100
committerStefan Bühler <stbuehler@web.de>2009-11-11 16:05:46 +0100
commit600ff698056a0b49525bea5ac3ab014ea0863ba5 (patch)
tree9852ab36dbf18251c2bb3825916d3671344fd572 /fcgi-cgi.c
parent2912f13047d92d9a2171e906d7a1735311365267 (diff)
downloadfcgi-cgi-600ff698056a0b49525bea5ac3ab014ea0863ba5.tar.gz
fcgi-cgi-600ff698056a0b49525bea5ac3ab014ea0863ba5.zip
Change directory before executing scripts
Diffstat (limited to 'fcgi-cgi.c')
-rw-r--r--fcgi-cgi.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/fcgi-cgi.c b/fcgi-cgi.c
index 68b2d7e..8272b92 100644
--- a/fcgi-cgi.c
+++ b/fcgi-cgi.c
@@ -9,6 +9,7 @@
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
+#include <string.h>
#include <stropts.h>
#include <sys/stat.h>
@@ -337,6 +338,17 @@ static void fcgi_cgi_child_start(fcgi_cgi_child *cld, const gchar *path) {
move2fd(pipes_from[1], 1);
move2fd(pipes_err[1], 2);
+ /* try changing the directory. don't care about memleaks, execve() coming soon :) */
+ {
+ char *dir = strdup(path), *sep;
+ if (NULL == (sep = strrchr(path, '/'))) {
+ chdir("/");
+ } else {
+ *sep = '\0';
+ chdir(dir);
+ }
+ }
+
g_ptr_array_add(enva, NULL);
newenv = (char**) g_ptr_array_free(enva, FALSE);
execve(path, args, newenv);
@@ -526,6 +538,8 @@ static void sigint_cb(struct ev_loop *loop, struct ev_signal *w, int revents) {
int main(int argc, char **argv) {
struct ev_loop *loop;
fcgi_cgi_server* srv;
+ UNUSED(argc);
+ UNUSED(argv);
loop = ev_default_loop(0);
srv = fcgi_cgi_server_create(loop, 0);