diff options
author | Roger Pau Monne <roger.pau@citrix.com> | 2012-05-23 11:06:47 +0100 |
---|---|---|
committer | Roger Pau Monne <roger.pau@citrix.com> | 2012-05-23 11:06:47 +0100 |
commit | a185e8dfa236dc0abcde8d234f0ee7d793c4fb68 (patch) | |
tree | 35d801f822a8e490933c230c3f227ed191352bf5 /tools/libxl/libxl_exec.c | |
parent | b25df336bd3b81c8245811effe8b3b6389078f88 (diff) | |
download | xen-a185e8dfa236dc0abcde8d234f0ee7d793c4fb68.tar.gz xen-a185e8dfa236dc0abcde8d234f0ee7d793c4fb68.tar.bz2 xen-a185e8dfa236dc0abcde8d234f0ee7d793c4fb68.zip |
libxl: pass env vars to libxl__exec
Add another parameter to libxl__exec call that contains the
environment variables to use when performing the execvp call.
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'tools/libxl/libxl_exec.c')
-rw-r--r-- | tools/libxl/libxl_exec.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/tools/libxl/libxl_exec.c b/tools/libxl/libxl_exec.c index b46b8939ae..082bf44ced 100644 --- a/tools/libxl/libxl_exec.c +++ b/tools/libxl/libxl_exec.c @@ -66,8 +66,8 @@ static void check_open_fds(const char *what) if (badness) abort(); } -void libxl__exec(int stdinfd, int stdoutfd, int stderrfd, const char *arg0, - char **args) +void libxl__exec(libxl__gc *gc, int stdinfd, int stdoutfd, int stderrfd, + const char *arg0, char *const args[], char *const env[]) /* call this in the child */ { if (stdinfd != -1) @@ -90,8 +90,18 @@ void libxl__exec(int stdinfd, int stdoutfd, int stderrfd, const char *arg0, /* in case our caller set it to IGN. subprocesses are entitled * to assume they got DFL. */ + if (env != NULL) { + for (int i = 0; env[i] != NULL && env[i+1] != NULL; i += 2) { + if (setenv(env[i], env[i+1], 1) < 0) { + LOGEV(ERROR, errno, "setting env vars (%s = %s)", + env[i], env[i+1]); + goto out; + } + } + } execvp(arg0, args); +out: fprintf(stderr, "libxl: cannot execute %s: %s\n", arg0, strerror(errno)); _exit(-1); } |