diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2009-11-09 19:54:28 +0000 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2009-11-09 19:54:28 +0000 |
commit | c5c301ac774d8cb36ccbc775bb7f1d7005d78a71 (patch) | |
tree | 8fcd7201e14424ae0b5041f186087e06639a69f6 /tools/libxl/libxl_exec.c | |
parent | 85f5921bdf8216ae1fd9cb5963f897562f1b2380 (diff) | |
download | xen-c5c301ac774d8cb36ccbc775bb7f1d7005d78a71.tar.gz xen-c5c301ac774d8cb36ccbc775bb7f1d7005d78a71.tar.bz2 xen-c5c301ac774d8cb36ccbc775bb7f1d7005d78a71.zip |
libxenlight: initial libxenlight implementation under tools/libxl
Signed-off-by: Vincent Hanquez <Vincent.Hanquez@eu.citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Diffstat (limited to 'tools/libxl/libxl_exec.c')
-rw-r--r-- | tools/libxl/libxl_exec.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tools/libxl/libxl_exec.c b/tools/libxl/libxl_exec.c new file mode 100644 index 0000000000..8d7928b4e8 --- /dev/null +++ b/tools/libxl/libxl_exec.c @@ -0,0 +1,48 @@ + +/* + * Copyright (C) 2009 Citrix Ltd. + * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com> + * Author Stefano Stabellini <stefano.stabellini@eu.citrix.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include "libxl.h" +#include "libxl_internal.h" + +int libxl_exec(struct libxl_ctx *ctx, int stdinfd, int stdoutfd, int stderrfd, + char *arg0, char **args) +{ + int pid, i; + + pid = fork(); + if (pid == -1) { + XL_LOG(ctx, XL_LOG_ERROR, "fork failed"); + return -1; + } + if (pid == 0) { + /* child */ + if (stdinfd != -1) + dup2(stdinfd, STDIN_FILENO); + if (stdoutfd != -1) + dup2(stdoutfd, STDOUT_FILENO); + if (stderrfd != -1) + dup2(stderrfd, STDERR_FILENO); + for (i = 4; i < 256; i++) + close(i); + execv(arg0, args); + exit(256); + } + return pid; +} |