aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxl/libxl_exec.c
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2010-04-12 17:41:05 +0100
committerKeir Fraser <keir.fraser@citrix.com>2010-04-12 17:41:05 +0100
commit25887df0dea37702586c16e1baf6681ed3ecd8de (patch)
treed2592225bcffb6d4fdc3c8abf92543a7c0b642dc /tools/libxl/libxl_exec.c
parent567326149cc6d9ba51e881604f3434f61a114f9d (diff)
downloadxen-25887df0dea37702586c16e1baf6681ed3ecd8de.tar.gz
xen-25887df0dea37702586c16e1baf6681ed3ecd8de.tar.bz2
xen-25887df0dea37702586c16e1baf6681ed3ecd8de.zip
libxl: Expose functions for helping with subprocesses.
* Expose libxl_fork in libxl_utils.h * Expose libxl_pipe in libxl_utils.h * Make libxl_exec put SIGPIPE back (so that libxl callers may have SIGPIPE ignored) xl would like to use libxl_fork (which is like fork(2) except that it logs errors) and also a similar function libxl_pipe. So put these in libxl_utils.[ch] and use them in libxl.c as appropriate, to avoid having to duplicate code between xl and libxl. Also, make sure that subprocesses spawned by libxl have SIGPIPE set back to SIG_DFL as they are entitled to expect. This means that a libxl caller which sets SIGPIPE to SIG_IGN is no longer buggy. (This is relevant for xl migration, because xl would like to be such a caller.) Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Diffstat (limited to 'tools/libxl/libxl_exec.c')
-rw-r--r--tools/libxl/libxl_exec.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/tools/libxl/libxl_exec.c b/tools/libxl/libxl_exec.c
index e8cc74c7da..6d4a5c5115 100644
--- a/tools/libxl/libxl_exec.c
+++ b/tools/libxl/libxl_exec.c
@@ -30,19 +30,6 @@
#include "libxl.h"
#include "libxl_internal.h"
-static pid_t libxl_fork(struct libxl_ctx *ctx)
-{
- pid_t pid;
-
- pid = fork();
- if (pid == -1) {
- XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "fork failed");
- return -1;
- }
-
- return pid;
-}
-
static int call_waitpid(pid_t (*waitpid_cb)(pid_t, int *, int), pid_t pid, int *status, int options)
{
return (waitpid_cb) ? waitpid_cb(pid, status, options) : waitpid(pid, status, options);
@@ -61,6 +48,11 @@ void libxl_exec(int stdinfd, int stdoutfd, int stderrfd, char *arg0, char **args
dup2(stderrfd, STDERR_FILENO);
for (i = 4; i < 256; i++)
close(i);
+
+ signal(SIGPIPE, SIG_DFL);
+ /* in case our caller set it to IGN. subprocesses are entitled
+ * to assume they got DFL. */
+
execv(arg0, args);
_exit(-1);
}