From nobody Thu May 16 01:08:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1645025613; cv=none; d=zohomail.com; s=zohoarc; b=PkKkHX3YC01SKMGUgEJ/gp3vIfC/YbNnmhqVTQkyY98iP88Fqac46MgYviP7+kyGX0amL4oCJrlqL1GvDQeSWfK9c3A/lysqr3xZUo2/4nOowSBsgM8yIhtEm/kBZzpR0rpoj7TYr3XsjEf/OPGizAyTkBPOwBTzDJFMvi5Z9QU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1645025613; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=OvKWlC5Mdk7d6jXsw3lcsqu/Hi6Rja/Ow9CWTpbo/NU=; b=XGkEHLvQc9YdcTgiRWDWykK1zhfQqKTNIuxzTycg+ra5kl8V0JpCyyp+bggbYIq+FPFwGhbIHee7qIzBXzLckLROmAMp/JU/ZCttEoBlnc5PHbb+NXYME49FiGKzltWZhrHxVf+l4JmjtXFxQ+9UVanN/D1SmiifpBHr66AHOdc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1645025613627280.4815613787365; Wed, 16 Feb 2022 07:33:33 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-10-kKhDyZScPyGBG8cgV81ghg-1; Wed, 16 Feb 2022 10:33:28 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 27BA38143E5; Wed, 16 Feb 2022 15:33:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 796DB7B036; Wed, 16 Feb 2022 15:33:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 20E8E4BB7B; Wed, 16 Feb 2022 15:33:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21GEwk2S013946 for ; Wed, 16 Feb 2022 09:58:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id DD74C1090082; Wed, 16 Feb 2022 14:58:46 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.245]) by smtp.corp.redhat.com (Postfix) with ESMTP id C707B109004F; Wed, 16 Feb 2022 14:58:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645025612; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=OvKWlC5Mdk7d6jXsw3lcsqu/Hi6Rja/Ow9CWTpbo/NU=; b=f+FozKM8GXmsPzVI2s0KAO+TeBjrctdekvS++ulpwmKkAU5DCncwuP9VxtmBKDzS7Ga9IS KAQ6vPY04mcS+uL7XSyxD1LJbOlDeZfj3lYQWEV4Psa5sm59ifKVMUkXypkcvQD4Xgb1BT MgdK5t6nfAMovv8tWjRNd0q2tz1H23o= X-MC-Unique: kKhDyZScPyGBG8cgV81ghg-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH] util: drop support for obsolete systemd in RHEL-7 Date: Wed, 16 Feb 2022 14:58:10 +0000 Message-Id: <20220216145810.1747359-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1645025614912100001 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=C3=A9 --- 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 =3D=3D 0) { g_autoptr(virSystemdActivation) act =3D NULL; - virSystemdActivationMap actmap[] =3D { - { .name =3D "virtlockd.socket", .family =3D AF_UNIX, .path =3D= sock_file }, - { .name =3D "virtlockd-admin.socket", .family =3D AF_UNIX, .pa= th =3D admin_sock_file }, - }; =20 if (godaemon) { if (chdir("/") < 0) { @@ -1016,9 +1012,7 @@ int main(int argc, char **argv) { goto cleanup; } =20 - if (virSystemdGetActivation(actmap, - G_N_ELEMENTS(actmap), - &act) < 0) { + if (virSystemdGetActivation(&act) < 0) { ret =3D 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 =3D=3D 0) { g_autoptr(virSystemdActivation) act =3D NULL; - virSystemdActivationMap actmap[] =3D { - { .name =3D "virtlogd.socket", .family =3D AF_UNIX, .path =3D = sock_file }, - { .name =3D "virtlogd-admin.socket", .family =3D AF_UNIX, .pat= h =3D admin_sock_file }, - }; =20 if (godaemon) { if (chdir("/") < 0) { @@ -824,9 +820,7 @@ int main(int argc, char **argv) { goto cleanup; } =20 - if (virSystemdGetActivation(actmap, - G_N_ELEMENTS(actmap), - &act) < 0) { + if (virSystemdGetActivation(&act) < 0) { ret =3D 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 =3D 0; #endif /* !WITH_SASL */ g_autoptr(virSystemdActivation) act =3D NULL; - virSystemdActivationMap actmap[] =3D { - { .name =3D DAEMON_NAME ".socket", .family =3D AF_UNIX, .path =3D = sock_path }, - { .name =3D DAEMON_NAME "-ro.socket", .family =3D AF_UNIX, .path = =3D sock_path_ro }, - { .name =3D DAEMON_NAME "-admin.socket", .family =3D AF_UNIX, .pat= h =3D sock_path_adm }, -#ifdef WITH_IP - { .name =3D DAEMON_NAME "-tcp.socket", .family =3D AF_INET }, - { .name =3D DAEMON_NAME "-tls.socket", .family =3D AF_INET }, -#endif /* ! WITH_IP */ - }; - -#ifdef WITH_IP - if ((actmap[3].port =3D virSocketAddrResolveService(config->tcp_port))= < 0) - return -1; - - if ((actmap[4].port =3D virSocketAddrResolveService(config->tls_port))= < 0) - return -1; -#endif /* ! WITH_IP */ =20 - if (virSystemdGetActivation(actmap, G_N_ELEMENTS(actmap), &act) < 0) + if (virSystemdGetActivation(&act) < 0) return -1; =20 #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, } =20 =20 -/* - * 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 =3D STDERR_FILENO + 1; - size_t i; - - while (nfds) { - virSocketAddr addr; - const char *name =3D NULL; - - memset(&addr, 0, sizeof(addr)); - - addr.len =3D sizeof(addr.data); - if (getsockname(nextfd, &addr.data.sa, &addr.len) < 0) { - virReportSystemError(errno, "%s", _("Unable to get local socke= t name")); - goto error; - } - - VIR_DEBUG("Got socket family %d for FD %d", - addr.data.sa.sa_family, nextfd); - - for (i =3D 0; i < nmap && !name; i++) { - if (map[i].name =3D=3D NULL) - continue; - - if (addr.data.sa.sa_family =3D=3D AF_INET) { - if (map[i].family =3D=3D AF_INET) { - VIR_DEBUG("Expect %d got %d", - map[i].port, ntohs(addr.data.inet4.sin_port)= ); - if (addr.data.inet4.sin_port =3D=3D htons(map[i].port)) - name =3D map[i].name; - } - } else if (addr.data.sa.sa_family =3D=3D 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 =3D=3D AF_INET) { - VIR_DEBUG("Expect %d got %d", - map[i].port, ntohs(addr.data.inet6.sin6_port= )); - if (addr.data.inet6.sin6_port =3D=3D htons(map[i].port= )) - name =3D map[i].name; - } -#ifndef WIN32 - } else if (addr.data.sa.sa_family =3D=3D AF_UNIX) { - if (map[i].family =3D=3D AF_UNIX) { - VIR_DEBUG("Expect %s got %s", map[i].path, addr.data.u= n.sun_path); - if (STREQLEN(map[i].path, - addr.data.un.sun_path, - sizeof(addr.data.un.sun_path))) - name =3D 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 =3D 0; i < nfds; i++) { - int fd =3D nextfd + i; - VIR_FORCE_CLOSE(fd); - } - return -1; -} - #ifndef WIN32 =20 /** @@ -954,9 +862,7 @@ virSystemdGetListenFDs(void) #endif /* WIN32 */ =20 static virSystemdActivation * -virSystemdActivationNew(virSystemdActivationMap *map, - size_t nmap, - int nfds) +virSystemdActivationNew(int nfds) { g_autoptr(virSystemdActivation) act =3D g_new0(virSystemdActivation, 1= ); const char *fdnames; @@ -966,14 +872,15 @@ virSystemdActivationNew(virSystemdActivationMap *map, act->fds =3D virHashNew(virSystemdActivationEntryFree); =20 fdnames =3D 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 a= ctivation")); + return NULL; } =20 + 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, =20 /** * 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 =3D 0; =20 @@ -1010,7 +913,7 @@ virSystemdGetActivation(virSystemdActivationMap *map, return 0; } =20 - *act =3D virSystemdActivationNew(map, nmap, nfds); + *act =3D virSystemdActivationNew(nfds); return 0; } =20 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 @@ =20 typedef struct _virSystemdActivation virSystemdActivation; =20 -/* - * 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 =3D=3D AF_INET/AF_INET6 */ - const char *path; /* if family =3D=3D AF_UNIX */ -} virSystemdActivationMap; - char *virSystemdMakeScopeName(const char *name, const char *drivername, bool legacy_behaviour); @@ -70,9 +59,7 @@ char *virSystemdGetMachineNameByPID(pid_t pid); =20 char *virSystemdGetMachineUnitByPID(pid_t pid); =20 -int virSystemdGetActivation(virSystemdActivationMap *map, - size_t nmap, - virSystemdActivation **act); +int virSystemdGetActivation(virSystemdActivation **act); =20 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, =20 =20 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 =3D NULL; size_t nfds =3D 0; g_autoptr(virSystemdActivation) act =3D NULL; @@ -544,21 +543,9 @@ testActivation(bool useNames) =20 g_setenv("LISTEN_FDS", nfdstr, TRUE); g_setenv("LISTEN_PID", pidstr, TRUE); + g_setenv("LISTEN_FDNAMES", virBufferCurrentContent(&names), TRUE); =20 - if (useNames) - g_setenv("LISTEN_FDNAMES", virBufferCurrentContent(&names), TRUE); - else - g_unsetenv("LISTEN_FDNAMES"); - - map[0].name =3D "demo-unix.socket"; - map[0].family =3D AF_UNIX; - map[0].path =3D demo_socket_path; - - map[1].name =3D "demo-ip.socket"; - map[1].family =3D AF_INET; - map[1].port =3D virNetSocketGetPort(sockIP[0]); - - if (virSystemdGetActivation(map, G_N_ELEMENTS(map), &act) < 0) + if (virSystemdGetActivation(&act) < 0) goto cleanup; =20 if (act =3D=3D NULL) { @@ -617,7 +604,7 @@ testActivationEmpty(const void *opaque G_GNUC_UNUSED) =20 g_unsetenv("LISTEN_FDS"); =20 - if (virSystemdGetActivation(NULL, 0, &act) < 0) + if (virSystemdGetActivation(&act) < 0) return -1; =20 if (act !=3D NULL) { @@ -629,21 +616,6 @@ testActivationEmpty(const void *opaque G_GNUC_UNUSED) return 0; } =20 - -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) =3D=3D -1 && errno =3D=3D EBADF)= { if (virTestRun("Test activation names", testActivationFDNames, NUL= L) < 0) ret =3D -1; - if (virTestRun("Test activation addrs", testActivationFDAddrs, NUL= L) < 0) - ret =3D -1; } else { VIR_INFO("Skipping activation tests as FD 3/4/5 is open"); } --=20 2.34.1