Re: [PATCH 1/3] utils: Implement virCommandPassFDGetFDIndex

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

 



On Mon, Feb 23, 2015 at 06:50:46AM -0500, Stefan Berger wrote:
Implement virCommandPassFDGetFDIndex to determine the index a given
file descriptor will have when passed to the child process. When this
function is called, a flag is set to prevent the reordering of the
file descriptors.

Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxxxxxxxxxx>
---
src/libvirt_private.syms |  1 +
src/util/vircommand.c    | 33 +++++++++++++++++++++++++++++++++
src/util/vircommand.h    |  3 +++
3 files changed, 37 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index c156b40..aadb833 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1213,6 +1213,7 @@ virCommandNewArgList;
virCommandNewArgs;
virCommandNonblockingFDs;
virCommandPassFD;
+virCommandPassFDGetFDIndex;
virCommandPassListenFDs;
virCommandRawStatus;
virCommandRequireHandshake;
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 6527d85..2616446 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -67,6 +67,7 @@ enum {
    VIR_EXEC_RUN_SYNC   = (1 << 3),
    VIR_EXEC_ASYNC_IO   = (1 << 4),
    VIR_EXEC_LISTEN_FDS = (1 << 5),
+    VIR_EXEC_FIXED_FDS  = (1 << 6),

The descriptors shouldn't get reordered *unless* there is
VIR_EXEC_LISTEN_FDS flag added, so FIXED_FDS shouldn't be necessary.
Or is there a bug in that approach that needs fixing?

};

typedef struct _virCommandFD virCommandFD;
@@ -214,6 +215,12 @@ virCommandReorderFDs(virCommandPtr cmd)
    if (!cmd || cmd->has_error || !cmd->npassfd)
        return;

+    if ((cmd->flags & VIR_EXEC_FIXED_FDS)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("The fds are fixed and cannot be reordered"));
+        goto error;
+    }
+
    for (i = 0; i < cmd->npassfd; i++)
        maxfd = MAX(cmd->passfd[i].fd, maxfd);

@@ -1019,6 +1026,32 @@ 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) {
+            cmd->flags |= VIR_EXEC_FIXED_FDS;
+            return i;
+        }
+        i++;
+    }
+
+    return -1;
+}
+
/**
 * virCommandSetPidFile:
 * @cmd: the command to modify
diff --git a/src/util/vircommand.h b/src/util/vircommand.h
index bf65de4..198da2f 100644
--- a/src/util/vircommand.h
+++ b/src/util/vircommand.h
@@ -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);

--
1.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

Attachment: pgpknQU4gIMpk.pgp
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]