]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: introduce virCommandPassFDIndex
authorJán Tomko <jtomko@redhat.com>
Tue, 24 Nov 2020 13:11:36 +0000 (14:11 +0100)
committerJán Tomko <jtomko@redhat.com>
Tue, 1 Dec 2020 16:24:20 +0000 (17:24 +0100)
Just like virCommandPassFD, but it also returns an index of
the passed FD in the FD set.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/libvirt_private.syms
src/util/vircommand.c
src/util/vircommand.h

index 581857deb964aaee2d499c689e40fe86ac167fa0..179dcecb0ad7bf229aa9aa7f1577d0556267fd11 100644 (file)
@@ -1884,6 +1884,7 @@ virCommandNewVAList;
 virCommandNonblockingFDs;
 virCommandPassFD;
 virCommandPassFDGetFDIndex;
+virCommandPassFDIndex;
 virCommandRawStatus;
 virCommandRequireHandshake;
 virCommandRun;
index 5117467c1d890b89a6b9fc3382992a4e2b32be66..e47dd6b932aa3c09c60e1ea440654c1ff6ca09f3 100644 (file)
@@ -999,10 +999,11 @@ virCommandNewVAList(const char *binary, va_list list)
         VIR_FORCE_CLOSE(fd)
 
 /**
- * virCommandPassFD:
+ * virCommandPassFDIndex:
  * @cmd: the command to modify
  * @fd: fd to reassign to the child
  * @flags: extra flags; binary-OR of virCommandPassFDFlags
+ * @idx: pointer to fill with the index of the FD in the transfer set
  *
  * Transfer the specified file descriptor to the child, instead
  * of closing it on exec. @fd must not be one of the three
@@ -1013,7 +1014,7 @@ virCommandNewVAList(const char *binary, va_list list)
  * should cease using the @fd when this call completes
  */
 void
-virCommandPassFD(virCommandPtr cmd, int fd, unsigned int flags)
+virCommandPassFDIndex(virCommandPtr cmd, int fd, unsigned int flags, size_t *idx)
 {
     int ret = 0;
 
@@ -1037,6 +1038,29 @@ virCommandPassFD(virCommandPtr cmd, int fd, unsigned int flags)
         VIR_COMMAND_MAYBE_CLOSE_FD(fd, flags);
         return;
     }
+
+    if (idx)
+        *idx = cmd->npassfd - 1;
+}
+
+/**
+ * virCommandPassFD:
+ * @cmd: the command to modify
+ * @fd: fd to reassign to the child
+ * @flags: extra flags; binary-OR of virCommandPassFDFlags
+ *
+ * Transfer the specified file descriptor to the child, instead
+ * of closing it on exec. @fd must not be one of the three
+ * standard streams.
+ *
+ * If the flag VIR_COMMAND_PASS_FD_CLOSE_PARENT is set then fd will
+ * be closed in the parent no later than Run/RunAsync/Free. The parent
+ * should cease using the @fd when this call completes
+ */
+void
+virCommandPassFD(virCommandPtr cmd, int fd, unsigned int flags)
+{
+    virCommandPassFDIndex(cmd, fd, flags, NULL);
 }
 
 /*
index e12c88bcc38c90a657b63238213124924aeac402..0ea6c8229f7ac6077c031fee5f9bdfefc96bc8f5 100644 (file)
@@ -57,6 +57,11 @@ void virCommandPassFD(virCommandPtr cmd,
                       int fd,
                       unsigned int flags) G_GNUC_NO_INLINE;
 
+void virCommandPassFDIndex(virCommandPtr cmd,
+                           int fd,
+                           unsigned int flags,
+                           size_t *idx) G_GNUC_NO_INLINE;
+
 int virCommandPassFDGetFDIndex(virCommandPtr cmd,
                                int fd);