From nobody Sat Feb 7 09:47:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1562854102; cv=none; d=zoho.com; s=zohoarc; b=j2VbDk8bWya/Z8meNr86Y275liGkVrCrvrhgFAfGB306dzu8iHjMOQ8DOkc3RL/ZX/ajfgz0dppdz2fyQUkR+gpiFUDmrnv9GDEORaZAYb1EF93GZArCYYN4WOzlDhmofCiKRgkyMhIARUx9GDTTuJqAKWk5+bKWph+bh3F1HKA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562854102; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=7VrPpicwJkc8lHjbu5ezkfXur37qHz3rNHasYDcJLQU=; b=hZA4XwmN8IJ5rhVnpLWf/afTKUEAWTrdQGzKppFs+BG1D19nOW8UOhiM+7po/PkAmPajpTc3ve8pp2463s3+bjKeuaC9i7dFB4/ivKmVql3oMDnBFUanWDcXMAngE+QLEclqYQCBJuUkHO2Gaa8x21E9iYRe98I7F+jceqgQHeY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1562854102943533.4832094718093; Thu, 11 Jul 2019 07:08:22 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 28196308338E; Thu, 11 Jul 2019 14:08:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0218D5D72E; Thu, 11 Jul 2019 14:08:21 +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 B43BD1833005; Thu, 11 Jul 2019 14:08:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6BE85h5028959 for ; Thu, 11 Jul 2019 10:08:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id CEF3660156; Thu, 11 Jul 2019 14:08:05 +0000 (UTC) Received: from dhcp-17-95.lcy.redhat.com (unknown [10.42.17.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58ECB6014C; Thu, 11 Jul 2019 14:08:04 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 15:07:40 +0100 Message-Id: <20190711140742.31029-18-berrange@redhat.com> In-Reply-To: <20190711140742.31029-1-berrange@redhat.com> References: <20190711140742.31029-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 17/19] util: move code for getting listen FDs into systemd module 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 11 Jul 2019 14:08:21 +0000 (UTC) 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=C3=A9 --- 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 1e32dd090e..11134e2e34 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3231,7 +3231,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(virSystemdActivationPt= r act, return -1; } =20 +#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 =3D 0; + unsigned long long procid; + unsigned int nfds; + + VIR_DEBUG("Setting up networking from caller"); + + if (!(pidstr =3D 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 !=3D getpid()) { + VIR_DEBUG("LISTEN_PID %s is not for us %lld", + pidstr, (long long) getpid()); + return 0; + } + + if (!(fdstr =3D 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 =3D 0; i < nfds; i++) { + int fd =3D 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 */ =20 static virSystemdActivationPtr virSystemdActivationNew(virSystemdActivationMap *map, @@ -812,7 +884,7 @@ virSystemdGetActivation(virSystemdActivationMap *map, { int nfds =3D 0; =20 - if ((nfds =3D virGetListenFDs()) < 0) + if ((nfds =3D virSystemdGetListenFDs()) < 0) return -1; =20 if (nfds =3D=3D 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) } } =20 -#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 =3D 0; - unsigned long long procid; - unsigned int nfds; - - VIR_DEBUG("Setting up networking from caller"); - - if (!(pidstr =3D 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 !=3D getpid()) { - VIR_DEBUG("LISTEN_PID %s is not for us %lld", - pidstr, (long long) getpid()); - return 0; - } - - if (!(fdstr =3D 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 =3D 0; i < nfds; i++) { - int fd =3D 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 */ =20 #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); =20 -unsigned int virGetListenFDs(void); char *virGetUNIXSocketPath(int fd); =20 long virGetSystemPageSize(void) ATTRIBUTE_NOINLINE; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list