[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 03 of 29 RFC] libxl: allow libxl__exec to take a parameter containing the env variables



# HG changeset patch
# User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
# Date 1328175734 -3600
# Node ID b380ea895013853efd335c3fba4fe22f27ce1de1
# Parent  9a8ccac7b5986622f76fb8c501d2ef500f2d77a1
libxl: allow libxl__exec to take a parameter containing the env variables

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@xxxxxxxxxxxxx>

diff -r 9a8ccac7b598 -r b380ea895013 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Fri Sep 30 14:38:55 2011 +0200
+++ b/tools/libxl/libxl.c       Thu Feb 02 10:42:14 2012 +0100
@@ -940,7 +940,7 @@ int libxl_vncviewer_exec(libxl_ctx *ctx,
         args[2] = "-autopass";
     }
 
-    libxl__exec(autopass_fd, -1, -1, args[0], args);
+    libxl__exec(autopass_fd, -1, -1, args[0], args, NULL);
     abort();
 
  x_fail:
diff -r 9a8ccac7b598 -r b380ea895013 tools/libxl/libxl_bootloader.c
--- a/tools/libxl/libxl_bootloader.c    Fri Sep 30 14:38:55 2011 +0200
+++ b/tools/libxl/libxl_bootloader.c    Thu Feb 02 10:42:14 2012 +0100
@@ -111,12 +111,12 @@ static int open_xenconsoled_pty(int *mas
 static pid_t fork_exec_bootloader(int *master, const char *arg0, char **args)
 {
     struct termios termattr;
+    char *env[] = {"TERM", "vt100", NULL};
     pid_t pid = forkpty(master, NULL, NULL, NULL);
     if (pid == -1)
         return -1;
     else if (pid == 0) {
-        setenv("TERM", "vt100", 1);
-        libxl__exec(-1, -1, -1, arg0, args);
+        libxl__exec(-1, -1, -1, arg0, args, env);
         return -1;
     }
 
diff -r 9a8ccac7b598 -r b380ea895013 tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c    Fri Sep 30 14:38:55 2011 +0200
+++ b/tools/libxl/libxl_dm.c    Thu Feb 02 10:42:14 2012 +0100
@@ -874,7 +874,7 @@ retry_transaction:
         goto out_close;
     if (!rc) { /* inner child */
         setsid();
-        libxl__exec(null, logfile_w, logfile_w, dm, args);
+        libxl__exec(null, logfile_w, logfile_w, dm, args, NULL);
     }
 
     rc = 0;
diff -r 9a8ccac7b598 -r b380ea895013 tools/libxl/libxl_exec.c
--- a/tools/libxl/libxl_exec.c  Fri Sep 30 14:38:55 2011 +0200
+++ b/tools/libxl/libxl_exec.c  Thu Feb 02 10:42:14 2012 +0100
@@ -72,7 +72,7 @@ static void check_open_fds(const char *w
 }
 
 void libxl__exec(int stdinfd, int stdoutfd, int stderrfd, const char *arg0,
-                char **args)
+                char **args, char **env)
      /* call this in the child */
 {
     if (stdinfd != -1)
@@ -95,6 +95,11 @@ void libxl__exec(int stdinfd, int stdout
     /* 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) {
+            setenv(env[i], env[i+1], 1);
+        }
+    }
     execvp(arg0, args);
 
     fprintf(stderr, "libxl: cannot execute %s: %s\n", arg0, strerror(errno));
diff -r 9a8ccac7b598 -r b380ea895013 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Fri Sep 30 14:38:55 2011 +0200
+++ b/tools/libxl/libxl_internal.h      Thu Feb 02 10:42:14 2012 +0100
@@ -479,7 +479,7 @@ typedef struct {
  /* low-level stuff, for synchronous subprocesses etc. */
 
 _hidden void libxl__exec(int stdinfd, int stdoutfd, int stderrfd,
-               const char *arg0, char **args); // logs errors, never returns
+               const char *arg0, char **args, char **env); // logs errors, 
never returns
 
 /* from xl_create */
 _hidden int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info, 
uint32_t *domid);

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.