aboutsummaryrefslogtreecommitdiff
path: root/fcgi-cgi.c
diff options
context:
space:
mode:
authorStefan Bühler <stbuehler@web.de>2013-07-20 15:16:15 +0200
committerStefan Bühler <stbuehler@web.de>2013-07-20 15:16:15 +0200
commitc699a147a12ce45790418fddefc8700b74b46d63 (patch)
treef3741645482d7ea3844cd653e2293cc14dcab941 /fcgi-cgi.c
parentb40d34f0c844a0457f4e816ea447d1b2103c9fcd (diff)
downloadfcgi-cgi-c699a147a12ce45790418fddefc8700b74b46d63.tar.gz
fcgi-cgi-c699a147a12ce45790418fddefc8700b74b46d63.zip
copy PATH environment variable
Diffstat (limited to 'fcgi-cgi.c')
-rw-r--r--fcgi-cgi.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/fcgi-cgi.c b/fcgi-cgi.c
index a67b865..c85236d 100644
--- a/fcgi-cgi.c
+++ b/fcgi-cgi.c
@@ -311,6 +311,32 @@ static void fcgi_cgi_child_error(fcgi_cgi_child *cld) {
}
}
+static void copy_env_var(GPtrArray *env, const char *name) {
+ guint i, namelen = strlen(name);
+ const char *value;
+
+ for (i = 0; i < env->len; ) {
+ const char *entry = g_ptr_array_index(env, i);
+ if (0 == strncmp(entry, name, namelen) && entry[namelen] == '=') {
+ g_ptr_array_remove_index_fast(env, i);
+ g_free((char*) entry);
+ } else {
+ ++i;
+ }
+ }
+
+ value = getenv(name);
+ if (NULL != value) {
+ guint valuelen = strlen(value);
+ char *entry = g_malloc(namelen + valuelen + 2);
+ memcpy(entry, name, namelen);
+ entry[namelen] = '=';
+ memcpy(entry + namelen + 1, value, valuelen);
+ entry[namelen+valuelen+1] = 0;
+ g_ptr_array_add(env, entry);
+ }
+}
+
static void fcgi_cgi_child_start(fcgi_cgi_child *cld, const gchar *path) {
int pipes_to[2] = {-1, -1}, pipes_from[2] = {-1, -1}, pipes_err[2] = {-1, -1};
pid_t pid;
@@ -353,6 +379,7 @@ static void fcgi_cgi_child_start(fcgi_cgi_child *cld, const gchar *path) {
}
}
+ copy_env_var(enva, "PATH");
g_ptr_array_add(enva, NULL);
newenv = (char**) g_ptr_array_free(enva, FALSE);
execve(path, args, newenv);