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

[Libvir] [PATCH 3/7] Add option to pass stdin fd to virExec



If nonzero, uses the supplied fd instead of /dev/null.
Update callers accordingly.

Signed-off-by: Jim Paris <jim jtan com>
---
 src/openvz_driver.c |    4 ++--
 src/qemu_driver.c   |    5 +++--
 src/util.c          |   12 ++++++------
 src/util.h          |    4 ++--
 4 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/openvz_driver.c b/src/openvz_driver.c
index 84d514c..b0788f6 100644
--- a/src/openvz_driver.c
+++ b/src/openvz_driver.c
@@ -342,7 +342,7 @@ static int openvzListDomains(virConnectPtr conn, int *ids, int nids) {
     char buf[32];
     const char *cmd[] = {VZLIST, "-ovpsid", "-H" , NULL};
 
-    ret = virExec(conn, (char **)cmd, &pid, &outfd, &errfd);
+    ret = virExec(conn, (char **)cmd, &pid, 0, &outfd, &errfd);
     if(ret == -1) {
         error(conn, VIR_ERR_INTERNAL_ERROR, "Could not exec " VZLIST);
         return (int)NULL;
@@ -373,7 +373,7 @@ static int openvzListDefinedDomains(virConnectPtr conn,
     const char *cmd[] = {VZLIST, "-ovpsid", "-H", NULL};
 
     /* the -S options lists only stopped domains */
-    ret = virExec(conn, (char **)cmd, &pid, &outfd, &errfd);
+    ret = virExec(conn, (char **)cmd, &pid, 0, &outfd, &errfd);
     if(ret == -1) {
         error(conn, VIR_ERR_INTERNAL_ERROR, "Could not exec " VZLIST);
         return (int)NULL;
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 8063ad2..553aa21 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -655,7 +655,8 @@ static int qemudStartVMDaemon(virConnectPtr conn,
         qemudLog(QEMUD_WARN, "Unable to write argv to logfile %d: %s",
                  errno, strerror(errno));
 
-    if (virExecNonBlock(conn, argv, &vm->pid, &vm->stdout, &vm->stderr) == 0) {
+    if (virExecNonBlock(conn, argv, &vm->pid, 
+                        0, &vm->stdout, &vm->stderr) == 0) {
         vm->id = driver->nextvmid++;
         vm->state = VIR_DOMAIN_RUNNING;
 
@@ -912,7 +913,7 @@ dhcpStartDhcpDaemon(virConnectPtr conn,
     if (qemudBuildDnsmasqArgv(conn, network, &argv) < 0)
         return -1;
 
-    ret = virExecNonBlock(conn, argv, &network->dnsmasqPid, NULL, NULL);
+    ret = virExecNonBlock(conn, argv, &network->dnsmasqPid, 0, NULL, NULL);
 
     for (i = 0; argv[i]; i++)
         free(argv[i]);
diff --git a/src/util.c b/src/util.c
index f53cfd2..546a7b8 100644
--- a/src/util.c
+++ b/src/util.c
@@ -79,7 +79,7 @@ static int virSetNonBlock(int fd) {
 static int
 _virExec(virConnectPtr conn,
           char **argv,
-          int *retpid, int *outfd, int *errfd, int non_block) {
+          int *retpid, int infd, int *outfd, int *errfd, int non_block) {
     int pid, null;
     int pipeout[2] = {-1,-1};
     int pipeerr[2] = {-1,-1};
@@ -140,7 +140,7 @@ _virExec(virConnectPtr conn,
     if (pipeerr[0] > 0 && close(pipeerr[0]) < 0)
         _exit(1);
 
-    if (dup2(null, STDIN_FILENO) < 0)
+    if (dup2(infd > 0 ? infd : null, STDIN_FILENO) < 0)
         _exit(1);
     if (dup2(pipeout[1] > 0 ? pipeout[1] : null, STDOUT_FILENO) < 0)
         _exit(1);
@@ -176,16 +176,16 @@ _virExec(virConnectPtr conn,
 int
 virExec(virConnectPtr conn,
           char **argv,
-          int *retpid, int *outfd, int *errfd) {
+          int *retpid, int infd, int *outfd, int *errfd) {
 
-    return(_virExec(conn, argv, retpid, outfd, errfd, 0));
+    return(_virExec(conn, argv, retpid, infd, outfd, errfd, 0));
 }
 
 int
 virExecNonBlock(virConnectPtr conn,
           char **argv,
-          int *retpid, int *outfd, int *errfd) {
+          int *retpid, int infd, int *outfd, int *errfd) {
 
-    return(_virExec(conn, argv, retpid, outfd, errfd, 1));
+    return(_virExec(conn, argv, retpid, infd, outfd, errfd, 1));
 }
 
diff --git a/src/util.h b/src/util.h
index 5b84043..d11e6d9 100644
--- a/src/util.h
+++ b/src/util.h
@@ -21,6 +21,6 @@
  * File created Jul 18, 2007 - Shuveb Hussain <shuveb binarykarma com>
  */
 
-int virExec(virConnectPtr conn, char **argv, int *retpid, int *outfd, int *errfd);
-int virExecNonBlock(virConnectPtr conn, char **argv, int *retpid, int *outfd, int *errfd);
+int virExec(virConnectPtr conn, char **argv, int *retpid, int infd, int *outfd, int *errfd);
+int virExecNonBlock(virConnectPtr conn, char **argv, int *retpid, int infd, int *outfd, int *errfd);
 
-- 
1.5.3.rc4


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