[PATCH 22/23] util: move code for getting listen FDs into systemd module

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

 



The virGetListenFDs method no longer needs to be called directly, so it
can be a static function internal to the systemd code.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/libvirt_private.syms |  1 -
 src/util/virsystemd.c    | 74 +++++++++++++++++++++++++++++++++++++++-
 src/util/virutil.c       | 72 --------------------------------------
 src/util/virutil.h       |  1 -
 4 files changed, 73 insertions(+), 75 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index c560dda5e8..37a8ff1285 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3247,7 +3247,6 @@ virGetGroupList;
 virGetGroupName;
 virGetHostname;
 virGetHostnameQuiet;
-virGetListenFDs;
 virGetSelfLastChanged;
 virGetSystemPageSize;
 virGetSystemPageSizeKB;
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index ae8401343d..f6c5adc5ef 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -756,6 +756,78 @@ virSystemdActivationInitFromMap(virSystemdActivationPtr act,
     return -1;
 }
 
+#ifndef WIN32
+
+/**
+ * virSystemdGetListenFDs:
+ *
+ * Parse LISTEN_PID and LISTEN_FDS passed from caller.
+ *
+ * Returns number of passed FDs.
+ */
+static unsigned int
+virSystemdGetListenFDs(void)
+{
+    const char *pidstr;
+    const char *fdstr;
+    size_t i = 0;
+    unsigned long long procid;
+    unsigned int nfds;
+
+    VIR_DEBUG("Setting up networking from caller");
+
+    if (!(pidstr = virGetEnvAllowSUID("LISTEN_PID"))) {
+        VIR_DEBUG("No LISTEN_PID from caller");
+        return 0;
+    }
+
+    if (virStrToLong_ull(pidstr, NULL, 10, &procid) < 0) {
+        VIR_DEBUG("Malformed LISTEN_PID from caller %s", pidstr);
+        return 0;
+    }
+
+    if ((pid_t)procid != getpid()) {
+        VIR_DEBUG("LISTEN_PID %s is not for us %lld",
+                  pidstr, (long long) getpid());
+        return 0;
+    }
+
+    if (!(fdstr = virGetEnvAllowSUID("LISTEN_FDS"))) {
+        VIR_DEBUG("No LISTEN_FDS from caller");
+        return 0;
+    }
+
+    if (virStrToLong_ui(fdstr, NULL, 10, &nfds) < 0) {
+        VIR_DEBUG("Malformed LISTEN_FDS from caller %s", fdstr);
+        return 0;
+    }
+
+    unsetenv("LISTEN_PID");
+    unsetenv("LISTEN_FDS");
+
+    VIR_DEBUG("Got %u file descriptors", nfds);
+
+    for (i = 0; i < nfds; i++) {
+        int fd = STDERR_FILENO + i + 1;
+
+        VIR_DEBUG("Disabling inheritance of passed FD %d", fd);
+
+        if (virSetInherit(fd, false) < 0)
+            VIR_WARN("Couldn't disable inheritance of passed FD %d", fd);
+    }
+
+    return nfds;
+}
+
+#else /* WIN32 */
+
+static unsigned int
+virSystemdGetListenFDs(void)
+{
+    return 0;
+}
+
+#endif /* WIN32 */
 
 static virSystemdActivationPtr
 virSystemdActivationNew(virSystemdActivationMap *map,
@@ -812,7 +884,7 @@ virSystemdGetActivation(virSystemdActivationMap *map,
 {
     int nfds = 0;
 
-    if ((nfds = virGetListenFDs()) < 0)
+    if ((nfds = virSystemdGetListenFDs()) < 0)
         return -1;
 
     if (nfds == 0) {
diff --git a/src/util/virutil.c b/src/util/virutil.c
index b85769d936..4bd719127b 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -1784,78 +1784,6 @@ void virUpdateSelfLastChanged(const char *path)
     }
 }
 
-#ifndef WIN32
-
-/**
- * virGetListenFDs:
- *
- * Parse LISTEN_PID and LISTEN_FDS passed from caller.
- *
- * Returns number of passed FDs.
- */
-unsigned int
-virGetListenFDs(void)
-{
-    const char *pidstr;
-    const char *fdstr;
-    size_t i = 0;
-    unsigned long long procid;
-    unsigned int nfds;
-
-    VIR_DEBUG("Setting up networking from caller");
-
-    if (!(pidstr = virGetEnvAllowSUID("LISTEN_PID"))) {
-        VIR_DEBUG("No LISTEN_PID from caller");
-        return 0;
-    }
-
-    if (virStrToLong_ull(pidstr, NULL, 10, &procid) < 0) {
-        VIR_DEBUG("Malformed LISTEN_PID from caller %s", pidstr);
-        return 0;
-    }
-
-    if ((pid_t)procid != getpid()) {
-        VIR_DEBUG("LISTEN_PID %s is not for us %lld",
-                  pidstr, (long long) getpid());
-        return 0;
-    }
-
-    if (!(fdstr = virGetEnvAllowSUID("LISTEN_FDS"))) {
-        VIR_DEBUG("No LISTEN_FDS from caller");
-        return 0;
-    }
-
-    if (virStrToLong_ui(fdstr, NULL, 10, &nfds) < 0) {
-        VIR_DEBUG("Malformed LISTEN_FDS from caller %s", fdstr);
-        return 0;
-    }
-
-    unsetenv("LISTEN_PID");
-    unsetenv("LISTEN_FDS");
-
-    VIR_DEBUG("Got %u file descriptors", nfds);
-
-    for (i = 0; i < nfds; i++) {
-        int fd = STDERR_FILENO + i + 1;
-
-        VIR_DEBUG("Disabling inheritance of passed FD %d", fd);
-
-        if (virSetInherit(fd, false) < 0)
-            VIR_WARN("Couldn't disable inheritance of passed FD %d", fd);
-    }
-
-    return nfds;
-}
-
-#else /* WIN32 */
-
-unsigned int
-virGetListenFDs(void)
-{
-    return 0;
-}
-
-#endif /* WIN32 */
 
 #ifdef HAVE_SYS_UN_H
 char *virGetUNIXSocketPath(int fd)
diff --git a/src/util/virutil.h b/src/util/virutil.h
index 67a21c86bd..b9715e5e66 100644
--- a/src/util/virutil.h
+++ b/src/util/virutil.h
@@ -149,7 +149,6 @@ bool virIsSUID(void);
 time_t virGetSelfLastChanged(void);
 void virUpdateSelfLastChanged(const char *path);
 
-unsigned int virGetListenFDs(void);
 char *virGetUNIXSocketPath(int fd);
 
 long virGetSystemPageSize(void) ATTRIBUTE_NOINLINE;
-- 
2.21.0

--
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]

  Powered by Linux