xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@entel.upc.edu>
To: xen-devel@lists.xensource.com
Subject: [PATCH 02 of 13 RFC] libxl: allow libxl__exec to take a parameter containing the env variables
Date: Wed, 18 Jan 2012 10:58:07 +0100	[thread overview]
Message-ID: <b9a79fd1b93d44cf7b9c.1326880687@loki.upc.es> (raw)
In-Reply-To: <patchbomb.1326880685@loki.upc.es>

# HG changeset patch
# User Roger Pau Monne <roger.pau@entel.upc.edu>
# Date 1324934702 -3600
# Node ID b9a79fd1b93d44cf7b9ccf288c9f5df169adeb4d
# Parent  25752ced44427caec863c3e64185429c39b28c3a
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@entel.upc.edu>

diff -r 25752ced4442 -r b9a79fd1b93d tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Fri Sep 30 14:38:55 2011 +0200
+++ b/tools/libxl/libxl.c	Mon Dec 26 22:25:02 2011 +0100
@@ -951,7 +951,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 25752ced4442 -r b9a79fd1b93d 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	Mon Dec 26 22:25:02 2011 +0100
@@ -116,12 +116,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 25752ced4442 -r b9a79fd1b93d 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	Mon Dec 26 22:25:02 2011 +0100
@@ -884,7 +884,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 25752ced4442 -r b9a79fd1b93d 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	Mon Dec 26 22:25:02 2011 +0100
@@ -83,7 +83,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)
@@ -106,6 +106,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 25752ced4442 -r b9a79fd1b93d 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	Mon Dec 26 22:25:02 2011 +0100
@@ -451,7 +451,7 @@ _hidden int libxl__spawn_check(libxl__gc
  /* 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);

  parent reply	other threads:[~2012-01-18  9:58 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-18  9:58 [PATCH 00 of 13 RFC] libxl: add hotplug script calling Roger Pau Monne
2012-01-18  9:58 ` [PATCH 01 of 13 RFC] hotplug/block: get the type of block device from file path (NetBSD) Roger Pau Monne
2012-01-18  9:58 ` Roger Pau Monne [this message]
2012-01-18  9:58 ` [PATCH 03 of 13 RFC] libxl: add libxl__forkexec function to libxl_exec Roger Pau Monne
2012-01-18  9:58 ` [PATCH 04 of 13 RFC] libxl: wait for devices to initialize upon addition to the domain Roger Pau Monne
2012-01-18  9:58 ` [PATCH 05 of 13 RFC] hotplug NetBSD: pass an action instead of a state to hotplug scripts Roger Pau Monne
2012-01-18  9:58 ` [PATCH 06 of 13 RFC] libxl: perform xenstore device cleanup from libxl Roger Pau Monne
2012-01-18  9:58 ` [PATCH 07 of 13 RFC] libxl: remove force parameter from libxl__device_remove Roger Pau Monne
2012-01-18  9:58 ` [PATCH 08 of 13 RFC] libxl: add better error checking on libxl__device_remove Roger Pau Monne
2012-01-18  9:58 ` [PATCH 09 of 13 RFC] libxl: destroy devices before device model Roger Pau Monne
2012-01-26 17:23   ` Stefano Stabellini
2012-01-26 18:46     ` Roger Pau Monné
2012-01-27 10:21     ` Roger Pau Monné
2012-01-18  9:58 ` [PATCH 10 of 13 RFC] libxl: execute hotplug scripts directly from libxl Roger Pau Monne
2012-01-18  9:58 ` [PATCH 11 of 13 RFC] libxl: add hotplug script calling for NetBSD Roger Pau Monne
2012-01-18  9:58 ` [PATCH 12 of 13 RFC] libxl: add hotplug script calls for Linux Roger Pau Monne
2012-01-18  9:58 ` [PATCH 13 of 13 RFC] rc.d NetBSD: don't start xenbackendd by default, only when xend needs it Roger Pau Monne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b9a79fd1b93d44cf7b9c.1326880687@loki.upc.es \
    --to=roger.pau@entel.upc.edu \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).