diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 581857deb9..179dcecb0a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1884,6 +1884,7 @@ virCommandNewVAList; virCommandNonblockingFDs; virCommandPassFD; virCommandPassFDGetFDIndex; +virCommandPassFDIndex; virCommandRawStatus; virCommandRequireHandshake; virCommandRun; diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 5117467c1d..e47dd6b932 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);