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>
---
src/libvirt_private.syms | 1 +
src/util/vircommand.c | 28 ++++++++++++++++++++++++++--
src/util/vircommand.h | 5 +++++
3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 79a23f34cb..08f16eedb4 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1883,6 +1883,7 @@ virCommandNewVAList;
virCommandNonblockingFDs;
virCommandPassFD;
virCommandPassFDGetFDIndex;
+virCommandPassFDIndex;
virCommandRawStatus;
virCommandRequireHandshake;
virCommandRun;
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 9a4f3d7f32..2b9f28a918 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -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);
}
/*
diff --git a/src/util/vircommand.h b/src/util/vircommand.h
index e12c88bcc3..0ea6c8229f 100644
--- a/src/util/vircommand.h
+++ b/src/util/vircommand.h
@@ -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);
--
2.26.2
© 2016 - 2024 Red Hat, Inc.