WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 4 of 9] libxl: add libxl__forkexec to execute hotplug

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 4 of 9] libxl: add libxl__forkexec to execute hotplug scripts
From: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
Date: Fri, 14 Oct 2011 15:35:36 +0200
Delivery-date: Fri, 14 Oct 2011 06:41:51 -0700
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:content-type:mime-version:content-transfer-encoding:subject :x-mercurial-node:message-id:in-reply-to:references:user-agent:date :from:to; bh=A2fOxr3fYG4+eD8RD3hu8GZbTH+eQW9lE9pyuP/01D4=; b=foI1yJyFonEhsnI9eTfNAV21n5XX3y707CWTH7HStgLI+Hi5zIxSqmZAUzBRQcqtM7 imkpe3kWwPj49PS1qJjbMpBrkWAq9DVsMnLC11OP/eu4mA5eIl1x4HXtoM2G/D1JZCQh G2AB+zbMQR+L4jCt8MM+szSyEgPRIiHp6ueqs=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1318599332@loki>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1318599332@loki>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.9.2
# HG changeset patch
# User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
# Date 1318592310 -7200
# Node ID 0235e192a519e29ac3d77e91fe59b38e6a6f06ef
# Parent  0865f90beac01012dd0ff4a86b07d8fb62575163
libxl: add libxl__forkexec to execute hotplug scripts

Add a new function to libxl_exec that performs a vfork and executes the passed 
arguments using libxl__exec.

Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>

diff -r 0865f90beac0 -r 0235e192a519 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  Fri Oct 14 13:38:30 2011 +0200
@@ -308,3 +308,25 @@ int libxl__spawn_check(libxl__gc *gc, vo
     for_spawn->intermediate = 0;
     return ERROR_FAIL;
 }
+
+int libxl__forkexec(libxl__gc *gc, int stdinfd, int stdoutfd,
+                    int stderrfd, char **args)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+
+    switch (vfork()) {
+    case -1:
+        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "failed to vfork\n");
+        return -1;
+    case 0:
+        libxl__exec(stdinfd, stdoutfd, stderrfd, args[0], args);
+        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "failed to execute %s\n",
+                         args[0]);
+        exit(EXIT_FAILURE);
+        break;
+    default:
+        wait(NULL);
+        break;
+    }
+    return 0;
+}
diff -r 0865f90beac0 -r 0235e192a519 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      Fri Oct 14 13:38:30 2011 +0200
@@ -342,6 +342,8 @@ _hidden int libxl__spawn_check(libxl__gc
 
 _hidden void libxl__exec(int stdinfd, int stdoutfd, int stderrfd,
                const char *arg0, char **args); // logs errors, never returns
+_hidden int libxl__forkexec(libxl__gc *gc, int stdinfd, int stdoutfd,
+                            int stderrfd, char **args);
 _hidden void libxl__log_child_exitstatus(libxl__gc *gc,
                                 const char *what, pid_t pid, int status);
 

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