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] libxl: add libxl__forkexec function to libxl_exec

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] libxl: add libxl__forkexec function to libxl_exec
From: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
Date: Mon, 07 Nov 2011 15:58:56 +0100
Cc: cyliu@xxxxxxxx
Delivery-date: Mon, 07 Nov 2011 07:02:29 -0800
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:user-agent:date:from:to:cc; bh=46K/nqu3J72VT2++I3JC4c5pjnHmtH8UdzJhEGpJjVA=; b=lyh/mkSGeMIBZdE6Hxt6Z99lX8G6Ud00+cON8SRjkneFIEfkcBR4ImbpoQMPcyb7HJ +W605ATxo2WG7hymYj9t01pfXznM7lwmQvjAk8RZgBmuGcRqj34wIo/P1VP5qBUKJln0 xsNfAozUbjsIY8ixg+nT25fGN2BNwretx8oqg=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
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>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.9.2
# HG changeset patch
# User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
# Date 1320677864 -3600
# Node ID df25a1143fcb3f8da24df033ac11d6e431992eb8
# Parent  26b36adc549cbb0856e15f59d3e69dd8255b3c3b
libxl: add libxl__forkexec function to libxl_exec

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

I was going to submit this as a part of the hotplug script calling from libxl 
series, but since it seems to be interesting for qcow/qcow2 support I decided 
to submit it separately.

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

diff -r 26b36adc549c -r df25a1143fcb 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 Nov 07 15:57:44 2011 +0100
@@ -450,6 +450,40 @@ int libxl__spawn_check(libxl__gc *gc, li
     return ERROR_FAIL;
 }
 
+int libxl__forkexec(libxl__gc *gc, int stdinfd, int stdoutfd,
+                    int stderrfd, char **args)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    int status;
+    int rc = 0;
+    pid_t pid = fork();
+
+    switch (pid) {
+    case -1:
+        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "fork failed\n");
+        rc = -1;
+        break;
+    case 0:
+        libxl__exec(stdinfd, stdoutfd, stderrfd, args[0], args);
+        /* libxl__exec never returns */
+    default:
+        while (waitpid(pid, &status, 0) < 0) {
+            if (errno != EINTR) {
+                LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "waitpid failed\n");
+                rc = -1;
+                break;
+            }
+        }
+        if (WIFEXITED(status)) {
+            rc = WEXITSTATUS(status);
+        } else {
+            rc = -1;
+        }
+        break;
+    }
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
diff -r 26b36adc549c -r df25a1143fcb 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 Nov 07 15:57:44 2011 +0100
@@ -389,6 +389,20 @@ _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
 
+/*
+ * libxl__forkexec - Executes a file synchronously
+ * gc: allocation pool
+ * stdinfd, stdoutfd, stderrfd: fds to pass to libxl__exec
+ * args: file to execute and arguments to pass in the following format
+ *      args[0]: file to execute
+ *      args[1]: first argument to pass to the called program
+ *      args[n]: nth argument to pass to the called program
+ *
+ * Returns 0 on success, and < 0 on error.
+ */
+_hidden int libxl__forkexec(libxl__gc *gc, int stdinfd, int stdoutfd,
+                            int stderrfd, char **args);
+
 /* from xl_create */
 _hidden int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info, 
uint32_t *domid);
 _hidden int libxl__domain_build(libxl__gc *gc,

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] libxl: add libxl__forkexec function to libxl_exec, Roger Pau Monne <=