]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
utils: Implement virCommandPassFDGetFDIndex
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Thu, 5 Mar 2015 23:57:06 +0000 (18:57 -0500)
committerStefan Berger <stefanb@linux.vnet.ibm.com>
Thu, 5 Mar 2015 23:57:06 +0000 (18:57 -0500)
Implement virCommandPassFDGetFDIndex to determine the index a given
file descriptor will have when passed to the child process.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
src/libvirt_private.syms
src/util/vircommand.c
src/util/vircommand.h

index c810cf70d1922bb4870c53fed9d78211612acd74..3c6fd33a02b68f379c2f6e934851dfa58df85b19 100644 (file)
@@ -1214,6 +1214,7 @@ virCommandNewArgList;
 virCommandNewArgs;
 virCommandNonblockingFDs;
 virCommandPassFD;
+virCommandPassFDGetFDIndex;
 virCommandPassListenFDs;
 virCommandRawStatus;
 virCommandRequireHandshake;
index 6527d85e58ca7b751c15ac9e6658baef0245562d..648f5ed65445c031b2ef1824f9de49fedcb6f189 100644 (file)
@@ -1019,6 +1019,30 @@ virCommandPassListenFDs(virCommandPtr cmd)
     cmd->flags |= VIR_EXEC_LISTEN_FDS;
 }
 
+/*
+ * virCommandPassFDGetFDIndex:
+ * @cmd: pointer to virCommand
+ * @fd: FD to get index of
+ *
+ * Determine the index of the FD in the transfer set.
+ *
+ * Returns index >= 0 if @set contains @fd,
+ * -1 otherwise.
+ */
+int
+virCommandPassFDGetFDIndex(virCommandPtr cmd, int fd)
+{
+    size_t i = 0;
+
+    while (i < cmd->npassfd) {
+        if (cmd->passfd[i].fd == fd)
+            return i;
+        i++;
+    }
+
+    return -1;
+}
+
 /**
  * virCommandSetPidFile:
  * @cmd: the command to modify
index bf65de4ff97ac01c33c8e757ca2c90d9560066c2..198da2f9e386826e32211ff4d4a0b218614a9b87 100644 (file)
@@ -62,6 +62,9 @@ void virCommandPassFD(virCommandPtr cmd,
 
 void virCommandPassListenFDs(virCommandPtr cmd);
 
+int virCommandPassFDGetFDIndex(virCommandPtr cmd,
+                               int fd);
+
 void virCommandSetPidFile(virCommandPtr cmd,
                           const char *pidfile) ATTRIBUTE_NONNULL(2);