From nobody Thu Dec 18 02:37:28 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1516381816086807.5996812560767; Fri, 19 Jan 2018 09:10:16 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 03CCFC099441; Fri, 19 Jan 2018 17:10:15 +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 512D360C8D; Fri, 19 Jan 2018 17:10:14 +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 993203FB1D; Fri, 19 Jan 2018 17:10:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0JH9RSR000994 for ; Fri, 19 Jan 2018 12:09:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0118B60CA1; Fri, 19 Jan 2018 17:09:27 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6179860C8D; Fri, 19 Jan 2018 17:09:26 +0000 (UTC) From: "Daniel P. Berrange" To: libvir-list@redhat.com Date: Fri, 19 Jan 2018 17:09:16 +0000 Message-Id: <20180119170918.14141-3-berrange@redhat.com> In-Reply-To: <20180119170918.14141-1-berrange@redhat.com> References: <20180119170918.14141-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/4] util: add virGetUNIXSocketPath helper 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: , MIME-Version: 1.0 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 19 Jan 2018 17:10:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When receiving multiple socket FDs from systemd, it is critical to know what socket address each corresponds to so we can setup the right protocols on each. Signed-off-by: Daniel P. Berrange --- src/util/virutil.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ src/util/virutil.h | 1 + 2 files changed, 46 insertions(+) diff --git a/src/util/virutil.c b/src/util/virutil.c index e9dbaf3d7a..8352e0f1f1 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -68,6 +68,10 @@ # include #endif =20 +#ifdef HAVE_SYS_UN_H +# include +#endif + #include "c-ctype.h" #include "mgetgroups.h" #include "virerror.h" @@ -1978,6 +1982,47 @@ virGetListenFDs(void) =20 #endif /* WIN32 */ =20 +#ifdef HAVE_SYS_UN_H +char *virGetUNIXSocketPath(int fd) +{ + struct sockaddr_storage ss =3D { 0 }; + struct sockaddr_un *un =3D (struct sockaddr_un *)&ss; + socklen_t len =3D sizeof(ss); + char *path; + + if (getsockname(fd, (struct sockaddr *)&ss, &len) < 0) { + virReportSystemError(errno, _("Unable to get address of FD %d"), f= d); + return NULL; + } + + if (ss.ss_family !=3D AF_UNIX) { + virReportSystemError(EINVAL, _("FD %d is not a UNIX socket, has af= =3D%d"), + fd, ss.ss_family); + return NULL; + } + + if (un->sun_path[0] =3D=3D '\0') + un->sun_path[0] =3D '@'; + + if (VIR_ALLOC_N(path, sizeof(un->sun_path) + 1) < 0) + return NULL; + + memcpy(path, un->sun_path, sizeof(un->sun_path)); + path[sizeof(un->sun_path)] =3D '\0'; + return path; +} + +#else /* HAVE_SYS_UN_H */ + +char *virGetUNIXSocketPath(int fd) +{ + virReportSystemError(ENOSYS, "%s", + _("UNIX sockets not supported on this platform"); + return NULL; +} + +#endif /* HAVE_SYS_UN_H */ + #ifndef WIN32 long virGetSystemPageSize(void) { diff --git a/src/util/virutil.h b/src/util/virutil.h index 9381ad5682..be0f6b0ea8 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -207,6 +207,7 @@ verify((int)VIR_TRISTATE_BOOL_NO =3D=3D (int)VIR_TRISTA= TE_SWITCH_OFF); verify((int)VIR_TRISTATE_BOOL_ABSENT =3D=3D (int)VIR_TRISTATE_SWITCH_ABSEN= T); =20 unsigned int virGetListenFDs(void); +char *virGetUNIXSocketPath(int fd); =20 long virGetSystemPageSize(void) ATTRIBUTE_NOINLINE; long virGetSystemPageSizeKB(void) ATTRIBUTE_NOINLINE; --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list