From c5c301ac774d8cb36ccbc775bb7f1d7005d78a71 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Mon, 9 Nov 2009 19:54:28 +0000 Subject: libxenlight: initial libxenlight implementation under tools/libxl Signed-off-by: Vincent Hanquez Signed-off-by: Stefano Stabellini --- tools/libxl/libxl_exec.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tools/libxl/libxl_exec.c (limited to 'tools/libxl/libxl_exec.c') 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 + * Author Stefano Stabellini + * + * 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 +#include +#include +#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; +} -- cgit v1.2.3