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

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



# 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


 


Rackspace

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