From feeb9503d238a5bd3f5689dd65388114cb306fe8 Mon Sep 17 00:00:00 2001 From: florian Date: Sun, 13 Apr 2014 08:46:20 +0000 Subject: httpd(8) did a chdir(2) to the directory containing the cgi script. As there might be scripts depending on this do the same in slowcgi(8). pointed out and OK ratchov@ --- slowcgi.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'slowcgi.c') diff --git a/slowcgi.c b/slowcgi.c index 7c914f6..8d947d3 100644 --- a/slowcgi.c +++ b/slowcgi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: slowcgi.c,v 1.28 2014/03/17 13:39:29 florian Exp $ */ +/* $OpenBSD: slowcgi.c,v 1.29 2014/04/13 08:46:20 florian Exp $ */ /* * Copyright (c) 2013 David Gwynne * Copyright (c) 2013 Florian Obser @@ -841,6 +841,7 @@ exec_cgi(struct request *c) pid_t pid; char *argv[2]; char **env; + char *path; i = 0; @@ -891,6 +892,14 @@ exec_cgi(struct request *c) close(s_out[1]); close(s_err[1]); + path = strrchr(c->script_name, '/'); + if (path != NULL) { + *path = '\0'; + if (chdir(c->script_name) == -1) + lwarn("cannot chdir to %s", c->script_name); + *path = '/'; + } + argv[0] = c->script_name; argv[1] = NULL; if ((env = calloc(c->env_count + 1, sizeof(char*))) == NULL) -- cgit v1.2.3-2-gb3c3