提交 da196338 编写于 作者: D Daniel P. Berrange

Fix QEMU domain creation by allowing virExec to preserve certain FDs

上级 2875ed81
......@@ -621,6 +621,10 @@ static int lxcControllerStart(virConnectPtr conn,
const char **largv = NULL;
pid_t child;
int status;
fd_set keepfd;
char appPtyStr[30];
FD_ZERO(&keepfd);
#define ADD_ARG_SPACE \
do { \
......@@ -644,11 +648,13 @@ static int lxcControllerStart(virConnectPtr conn,
goto no_memory; \
} while (0)
snprintf(appPtyStr, sizeof(appPtyStr), "%d", appPty);
ADD_ARG_LIT(vm->def->emulator);
ADD_ARG_LIT("--name");
ADD_ARG_LIT(vm->def->name);
ADD_ARG_LIT("--console");
ADD_ARG_LIT("0"); /* Passing console master PTY as FD 0 */
ADD_ARG_LIT(appPtyStr);
ADD_ARG_LIT("--background");
for (i = 0 ; i < nveths ; i++) {
......@@ -658,10 +664,12 @@ static int lxcControllerStart(virConnectPtr conn,
ADD_ARG(NULL);
vm->stdin_fd = appPty; /* Passing console master PTY as FD 0 */
vm->stdin_fd = -1;
vm->stdout_fd = vm->stderr_fd = logfd;
if (virExec(conn, largv, NULL, &child,
FD_SET(appPty, &keepfd);
if (virExec(conn, largv, NULL, &keepfd, &child,
vm->stdin_fd, &vm->stdout_fd, &vm->stderr_fd,
VIR_EXEC_NONE) < 0)
goto cleanup;
......
......@@ -847,6 +847,9 @@ static int qemudStartVMDaemon(virConnectPtr conn,
int *tapfds = NULL;
int ntapfds = 0;
int qemuCmdFlags;
fd_set keepfd;
FD_ZERO(&keepfd);
if (virDomainIsActive(vm)) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
......@@ -950,7 +953,10 @@ static int qemudStartVMDaemon(virConnectPtr conn,
vm->stdout_fd = -1;
vm->stderr_fd = -1;
ret = virExec(conn, argv, NULL, &vm->pid,
for (i = 0 ; i < ntapfds ; i++)
FD_SET(tapfds[i], &keepfd);
ret = virExec(conn, argv, NULL, &keepfd, &vm->pid,
vm->stdin_fd, &vm->stdout_fd, &vm->stderr_fd,
VIR_EXEC_NONBLOCK);
if (ret == 0) {
......@@ -1219,7 +1225,8 @@ dhcpStartDhcpDaemon(virConnectPtr conn,
if (qemudBuildDnsmasqArgv(conn, network, &argv) < 0)
return -1;
ret = virExec(conn, argv, NULL, &network->dnsmasqPid, -1, NULL, NULL, VIR_EXEC_NONBLOCK);
ret = virExec(conn, argv, NULL, NULL,
&network->dnsmasqPid, -1, NULL, NULL, VIR_EXEC_NONBLOCK);
for (i = 0; argv[i]; i++)
VIR_FREE(argv[i]);
......
......@@ -403,7 +403,8 @@ virStorageBackendRunProgRegex(virConnectPtr conn,
/* Run the program and capture its output */
if (virExec(conn, prog, NULL, &child, -1, &fd, NULL, VIR_EXEC_NONE) < 0) {
if (virExec(conn, prog, NULL, NULL,
&child, -1, &fd, NULL, VIR_EXEC_NONE) < 0) {
goto cleanup;
}
......@@ -537,7 +538,8 @@ virStorageBackendRunProgNul(virConnectPtr conn,
v[i] = NULL;
/* Run the program and capture its output */
if (virExec(conn, prog, NULL, &child, -1, &fd, NULL, VIR_EXEC_NONE) < 0) {
if (virExec(conn, prog, NULL, NULL,
&child, -1, &fd, NULL, VIR_EXEC_NONE) < 0) {
goto cleanup;
}
......
......@@ -132,6 +132,7 @@ int
virExec(virConnectPtr conn,
const char *const*argv,
const char *const*envp,
const fd_set *keepfd,
int *retpid,
int infd, int *outfd, int *errfd,
int flags) {
......@@ -293,7 +294,9 @@ virExec(virConnectPtr conn,
if (i != infd &&
i != null &&
i != childout &&
i != childerr)
i != childerr &&
(!keepfd ||
!FD_ISSET(i, keepfd)))
close(i);
if (flags & VIR_EXEC_DAEMON) {
......@@ -403,7 +406,8 @@ virRun(virConnectPtr conn,
int *status) {
int childpid, exitstatus, ret;
if ((ret = virExec(conn, argv, NULL, &childpid, -1, NULL, NULL, VIR_EXEC_NONE)) < 0)
if ((ret = virExec(conn, argv, NULL, NULL,
&childpid, -1, NULL, NULL, VIR_EXEC_NONE)) < 0)
return ret;
while ((ret = waitpid(childpid, &exitstatus, 0) == -1) && errno == EINTR);
......
......@@ -26,6 +26,7 @@
#include "util-lib.h"
#include "verify.h"
#include <sys/select.h>
enum {
VIR_EXEC_NONE = 0,
......@@ -36,6 +37,7 @@ enum {
int virExec(virConnectPtr conn,
const char *const*argv,
const char *const*envp,
const fd_set *keepfd,
int *retpid,
int infd,
int *outfd,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册