[libvirt PATCH] util: drop support for obsolete systemd in RHEL-7

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

 



The systemd version in RHEL-7 lacked support for the LISTEN_FDNAMES env
variable with socket activation. Since we stopped targetting RHEL-7 we
can drop some considerable amount of compatibility code.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/locking/lock_daemon.c  |   8 +--
 src/logging/log_daemon.c   |   8 +--
 src/remote/remote_daemon.c |  19 +-----
 src/util/virsystemd.c      | 117 ++++---------------------------------
 src/util/virsystemd.h      |  15 +----
 tests/virsystemdtest.c     |  38 ++----------
 6 files changed, 18 insertions(+), 187 deletions(-)

diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index b44649bfbe..178e8cf830 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -986,10 +986,6 @@ int main(int argc, char **argv) {
      * saved state is present, therefore initialize from scratch here. */
     if (rv == 0) {
         g_autoptr(virSystemdActivation) act = NULL;
-        virSystemdActivationMap actmap[] = {
-            { .name = "virtlockd.socket", .family = AF_UNIX, .path = sock_file },
-            { .name = "virtlockd-admin.socket", .family = AF_UNIX, .path = admin_sock_file },
-        };
 
         if (godaemon) {
             if (chdir("/") < 0) {
@@ -1016,9 +1012,7 @@ int main(int argc, char **argv) {
             goto cleanup;
         }
 
-        if (virSystemdGetActivation(actmap,
-                                    G_N_ELEMENTS(actmap),
-                                    &act) < 0) {
+        if (virSystemdGetActivation(&act) < 0) {
             ret = VIR_DAEMON_ERR_NETWORK;
             goto cleanup;
         }
diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c
index 245df9dbbd..82f625142b 100644
--- a/src/logging/log_daemon.c
+++ b/src/logging/log_daemon.c
@@ -794,10 +794,6 @@ int main(int argc, char **argv) {
      */
     if (rv == 0) {
         g_autoptr(virSystemdActivation) act = NULL;
-        virSystemdActivationMap actmap[] = {
-            { .name = "virtlogd.socket", .family = AF_UNIX, .path = sock_file },
-            { .name = "virtlogd-admin.socket", .family = AF_UNIX, .path = admin_sock_file },
-        };
 
         if (godaemon) {
             if (chdir("/") < 0) {
@@ -824,9 +820,7 @@ int main(int argc, char **argv) {
             goto cleanup;
         }
 
-        if (virSystemdGetActivation(actmap,
-                                    G_N_ELEMENTS(actmap),
-                                    &act) < 0) {
+        if (virSystemdGetActivation(&act) < 0) {
             ret = VIR_DAEMON_ERR_NETWORK;
             goto cleanup;
         }
diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c
index 1b8e982a2f..26469e0d9f 100644
--- a/src/remote/remote_daemon.c
+++ b/src/remote/remote_daemon.c
@@ -214,25 +214,8 @@ daemonSetupNetworking(virNetServer *srv,
     unsigned int tcp_min_ssf = 0;
 #endif /* !WITH_SASL */
     g_autoptr(virSystemdActivation) act = NULL;
-    virSystemdActivationMap actmap[] = {
-        { .name = DAEMON_NAME ".socket", .family = AF_UNIX, .path = sock_path },
-        { .name = DAEMON_NAME "-ro.socket", .family = AF_UNIX, .path = sock_path_ro },
-        { .name = DAEMON_NAME "-admin.socket", .family = AF_UNIX, .path = sock_path_adm },
-#ifdef WITH_IP
-        { .name = DAEMON_NAME "-tcp.socket", .family = AF_INET },
-        { .name = DAEMON_NAME "-tls.socket", .family = AF_INET },
-#endif /* ! WITH_IP */
-    };
-
-#ifdef WITH_IP
-    if ((actmap[3].port = virSocketAddrResolveService(config->tcp_port)) < 0)
-        return -1;
-
-    if ((actmap[4].port = virSocketAddrResolveService(config->tls_port)) < 0)
-        return -1;
-#endif /* ! WITH_IP */
 
-    if (virSystemdGetActivation(actmap, G_N_ELEMENTS(actmap), &act) < 0)
+    if (virSystemdGetActivation(&act) < 0)
         return -1;
 
 #ifdef WITH_IP
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index a86d4c6bb9..c95b6c93d3 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -788,98 +788,6 @@ virSystemdActivationInitFromNames(virSystemdActivation *act,
 }
 
 
-/*
- * Back compat for systemd < v227 which lacks LISTEN_FDNAMES.
- * Delete when min systemd is increased ie RHEL7 dropped
- */
-static int
-virSystemdActivationInitFromMap(virSystemdActivation *act,
-                                int nfds,
-                                virSystemdActivationMap *map,
-                                size_t nmap)
-{
-    int nextfd = STDERR_FILENO + 1;
-    size_t i;
-
-    while (nfds) {
-        virSocketAddr addr;
-        const char *name = NULL;
-
-        memset(&addr, 0, sizeof(addr));
-
-        addr.len = sizeof(addr.data);
-        if (getsockname(nextfd, &addr.data.sa, &addr.len) < 0) {
-            virReportSystemError(errno, "%s", _("Unable to get local socket name"));
-            goto error;
-        }
-
-        VIR_DEBUG("Got socket family %d for FD %d",
-                  addr.data.sa.sa_family, nextfd);
-
-        for (i = 0; i < nmap && !name; i++) {
-            if (map[i].name == NULL)
-                continue;
-
-            if (addr.data.sa.sa_family == AF_INET) {
-                if (map[i].family == AF_INET) {
-                    VIR_DEBUG("Expect %d got %d",
-                              map[i].port, ntohs(addr.data.inet4.sin_port));
-                    if (addr.data.inet4.sin_port == htons(map[i].port))
-                        name = map[i].name;
-                }
-            } else if (addr.data.sa.sa_family == AF_INET6) {
-                /* NB use of AF_INET here is correct. The "map" struct
-                 * only refers to AF_INET. The socket may be AF_INET
-                 * or AF_INET6
-                 */
-                if (map[i].family == AF_INET) {
-                    VIR_DEBUG("Expect %d got %d",
-                              map[i].port, ntohs(addr.data.inet6.sin6_port));
-                    if (addr.data.inet6.sin6_port == htons(map[i].port))
-                        name = map[i].name;
-                }
-#ifndef WIN32
-            } else if (addr.data.sa.sa_family == AF_UNIX) {
-                if (map[i].family == AF_UNIX) {
-                    VIR_DEBUG("Expect %s got %s", map[i].path, addr.data.un.sun_path);
-                    if (STREQLEN(map[i].path,
-                                 addr.data.un.sun_path,
-                                 sizeof(addr.data.un.sun_path)))
-                        name = map[i].name;
-                }
-#endif
-            } else {
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               _("Unexpected socket family %d"),
-                               addr.data.sa.sa_family);
-                goto error;
-            }
-        }
-
-        if (!name) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Cannot find name for FD %d socket family %d"),
-                           nextfd, addr.data.sa.sa_family);
-            goto error;
-        }
-
-        if (virSystemdActivationAddFD(act, name, nextfd) < 0)
-            goto error;
-
-        nfds--;
-        nextfd++;
-    }
-
-    return 0;
-
- error:
-    for (i = 0; i < nfds; i++) {
-        int fd = nextfd + i;
-        VIR_FORCE_CLOSE(fd);
-    }
-    return -1;
-}
-
 #ifndef WIN32
 
 /**
@@ -954,9 +862,7 @@ virSystemdGetListenFDs(void)
 #endif /* WIN32 */
 
 static virSystemdActivation *
-virSystemdActivationNew(virSystemdActivationMap *map,
-                        size_t nmap,
-                        int nfds)
+virSystemdActivationNew(int nfds)
 {
     g_autoptr(virSystemdActivation) act = g_new0(virSystemdActivation, 1);
     const char *fdnames;
@@ -966,14 +872,15 @@ virSystemdActivationNew(virSystemdActivationMap *map,
     act->fds = virHashNew(virSystemdActivationEntryFree);
 
     fdnames = getenv("LISTEN_FDNAMES");
-    if (fdnames) {
-        if (virSystemdActivationInitFromNames(act, nfds, fdnames) < 0)
-            return NULL;
-    } else {
-        if (virSystemdActivationInitFromMap(act, nfds, map, nmap) < 0)
-            return NULL;
+    if (!fdnames) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Missing LISTEN_FDNAMES env from systemd socket activation"));
+        return NULL;
     }
 
+    if (virSystemdActivationInitFromNames(act, nfds, fdnames) < 0)
+        return NULL;
+
     VIR_DEBUG("Created activation object for %d FDs", nfds);
     return g_steal_pointer(&act);
 }
@@ -981,8 +888,6 @@ virSystemdActivationNew(virSystemdActivationMap *map,
 
 /**
  * virSystemdGetActivation:
- * @map: mapping of socket addresses to names
- * @nmap: number of entries in @map
  * @act: filled with allocated activation object
  *
  * Acquire an object for handling systemd activation.
@@ -995,9 +900,7 @@ virSystemdActivationNew(virSystemdActivationMap *map,
  * Returns: 0 on success, -1 on failure
  */
 int
-virSystemdGetActivation(virSystemdActivationMap *map,
-                        size_t nmap,
-                        virSystemdActivation **act)
+virSystemdGetActivation(virSystemdActivation **act)
 {
     int nfds = 0;
 
@@ -1010,7 +913,7 @@ virSystemdGetActivation(virSystemdActivationMap *map,
         return 0;
     }
 
-    *act = virSystemdActivationNew(map, nmap, nfds);
+    *act = virSystemdActivationNew(nfds);
     return 0;
 }
 
diff --git a/src/util/virsystemd.h b/src/util/virsystemd.h
index 93320e40b9..19fb714132 100644
--- a/src/util/virsystemd.h
+++ b/src/util/virsystemd.h
@@ -25,17 +25,6 @@
 
 typedef struct _virSystemdActivation virSystemdActivation;
 
-/*
- * Back compat for systemd < v227 which lacks LISTEN_FDNAMES.
- * Delete when min systemd is increased ie RHEL7 dropped
- */
-typedef struct _virSystemdActivationMap {
-    const char *name;
-    int family;
-    int port; /* if family == AF_INET/AF_INET6 */
-    const char *path; /* if family == AF_UNIX */
-} virSystemdActivationMap;
-
 char *virSystemdMakeScopeName(const char *name,
                               const char *drivername,
                               bool legacy_behaviour);
@@ -70,9 +59,7 @@ char *virSystemdGetMachineNameByPID(pid_t pid);
 
 char *virSystemdGetMachineUnitByPID(pid_t pid);
 
-int virSystemdGetActivation(virSystemdActivationMap *map,
-                            size_t nmap,
-                            virSystemdActivation **act);
+int virSystemdGetActivation(virSystemdActivation **act);
 
 bool virSystemdActivationHasName(virSystemdActivation *act,
                                  const char *name);
diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c
index 9a063dd1fc..9b513697e0 100644
--- a/tests/virsystemdtest.c
+++ b/tests/virsystemdtest.c
@@ -513,7 +513,7 @@ testActivationCreateFDs(virNetSocket **sockUNIX,
 
 
 static int
-testActivation(bool useNames)
+testActivationFDNames(const void *opaque G_GNUC_UNUSED)
 {
     virNetSocket *sockUNIX;
     virNetSocket **sockIP;
@@ -522,7 +522,6 @@ testActivation(bool useNames)
     size_t i;
     char nfdstr[VIR_INT64_STR_BUFLEN];
     char pidstr[VIR_INT64_STR_BUFLEN];
-    virSystemdActivationMap map[2];
     int *fds = NULL;
     size_t nfds = 0;
     g_autoptr(virSystemdActivation) act = NULL;
@@ -544,21 +543,9 @@ testActivation(bool useNames)
 
     g_setenv("LISTEN_FDS", nfdstr, TRUE);
     g_setenv("LISTEN_PID", pidstr, TRUE);
+    g_setenv("LISTEN_FDNAMES", virBufferCurrentContent(&names), TRUE);
 
-    if (useNames)
-        g_setenv("LISTEN_FDNAMES", virBufferCurrentContent(&names), TRUE);
-    else
-        g_unsetenv("LISTEN_FDNAMES");
-
-    map[0].name = "demo-unix.socket";
-    map[0].family = AF_UNIX;
-    map[0].path = demo_socket_path;
-
-    map[1].name = "demo-ip.socket";
-    map[1].family = AF_INET;
-    map[1].port = virNetSocketGetPort(sockIP[0]);
-
-    if (virSystemdGetActivation(map, G_N_ELEMENTS(map), &act) < 0)
+    if (virSystemdGetActivation(&act) < 0)
         goto cleanup;
 
     if (act == NULL) {
@@ -617,7 +604,7 @@ testActivationEmpty(const void *opaque G_GNUC_UNUSED)
 
     g_unsetenv("LISTEN_FDS");
 
-    if (virSystemdGetActivation(NULL, 0, &act) < 0)
+    if (virSystemdGetActivation(&act) < 0)
         return -1;
 
     if (act != NULL) {
@@ -629,21 +616,6 @@ testActivationEmpty(const void *opaque G_GNUC_UNUSED)
     return 0;
 }
 
-
-static int
-testActivationFDNames(const void *opaque G_GNUC_UNUSED)
-{
-    return testActivation(true);
-}
-
-
-static int
-testActivationFDAddrs(const void *opaque G_GNUC_UNUSED)
-{
-    return testActivation(false);
-}
-
-
 static int
 mymain(void)
 {
@@ -759,8 +731,6 @@ mymain(void)
         fcntl(STDERR_FILENO + 3, F_GETFL) == -1 && errno == EBADF) {
         if (virTestRun("Test activation names", testActivationFDNames, NULL) < 0)
             ret = -1;
-        if (virTestRun("Test activation addrs", testActivationFDAddrs, NULL) < 0)
-            ret = -1;
     } else {
         VIR_INFO("Skipping activation tests as FD 3/4/5 is open");
     }
-- 
2.34.1




[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