From nobody Sat Feb 7 09:47:20 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=1562854099; cv=none; d=zoho.com; s=zohoarc; b=CdDwEvZ6nNFe7QUT0GgKYwY59PYhz+K5G1doLf4nxhwZX7UMXtJ3UTUqp04JT3J3nmsnfaQMSPKx9b+4SgwUHrYIT5pgKNHsdBbJAkBvQ08ag6N4BqFfOQtgFfFEEDkfRcFHx+zJMoOAgM1cMzzMEqrOeVs7e5PZbXFdzxXdVig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562854099; 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=8PhBuMhFxV2LkcnErdyh95Is3/QXXhOCLb0+alCdLwE=; b=ZnvH7fTTMNHwfwH6s20mofaOkFIPbMq2ormsNeMNgsvH4JuypI6ASAfy6+qykbmPtBT7OgDlHtaodg12Gm5+Vj/TIqFBpYGsYh1NGPxIw+fp/hICGQGtq6WeGT5c3a6aaRcLZA10WbfTp8XAuVTmpQDuIGm3Hsvj+h2z41moITI= 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 15628540992081003.4092534428032; Thu, 11 Jul 2019 07:08:19 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 824E1308A951; Thu, 11 Jul 2019 14:08:17 +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 577BC60148; Thu, 11 Jul 2019 14:08:17 +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 F32751D575; Thu, 11 Jul 2019 14:08:16 +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 x6BE84co028948 for ; Thu, 11 Jul 2019 10:08:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 187B76015E; Thu, 11 Jul 2019 14:08:04 +0000 (UTC) Received: from dhcp-17-95.lcy.redhat.com (unknown [10.42.17.95]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8760660150; Thu, 11 Jul 2019 14:08:00 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 11 Jul 2019 15:07:39 +0100 Message-Id: <20190711140742.31029-17-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 16/19] logging: convert log daemon to use systemd activation APIs 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 11 Jul 2019 14:08:18 +0000 (UTC) Using the new system activation APIs allows for simpler code setting up the network services. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/logging/log_daemon.c | 125 ++++++++++++--------------------------- 1 file changed, 37 insertions(+), 88 deletions(-) diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index 30c70a20dd..8df04dbab1 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -517,78 +517,6 @@ virLogDaemonSetupSignals(virNetDaemonPtr dmn) } =20 =20 -static int -virLogDaemonSetupNetworkingSystemD(virNetServerPtr logSrv, virNetServerPtr= adminSrv) -{ - unsigned int nfds; - size_t i; - - if ((nfds =3D virGetListenFDs()) =3D=3D 0) - return 0; - if (nfds > 2) - VIR_DEBUG("Too many (%d) file descriptors from systemd", nfds); - - for (i =3D 0; i < nfds && i < 2; i++) { - virNetServerServicePtr svc; - char *path =3D virGetUNIXSocketPath(3 + i); - virNetServerPtr srv; - int fds[] =3D { 3 + i }; - - if (!path) - return -1; - - if (strstr(path, "virtlogd-admin-sock")) { - srv =3D adminSrv; - } else if (strstr(path, "virtlogd-sock")) { - srv =3D logSrv; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown UNIX socket %s passed in"), - path); - VIR_FREE(path); - return -1; - } - VIR_FREE(path); - - /* Systemd passes FDs, starting immediately after stderr, - * so the first FD we'll get is '3'. */ - if (!(svc =3D virNetServerServiceNewFDs(fds, - ARRAY_CARDINALITY(fds), - false, - 0, - NULL, - false, 0, 1))) - return -1; - - if (virNetServerAddService(srv, svc) < 0) { - virObjectUnref(svc); - return -1; - } - } - return 1; -} - - -static int -virLogDaemonSetupNetworkingNative(virNetServerPtr srv, const char *sock_pa= th) -{ - virNetServerServicePtr svc; - - VIR_DEBUG("Setting up networking natively"); - - if (!(svc =3D virNetServerServiceNewUNIX(sock_path, 0700, 0, 0, - NULL, - false, 0, 1))) - return -1; - - if (virNetServerAddService(srv, svc) < 0) { - virObjectUnref(svc); - return -1; - } - return 0; -} - - static void virLogDaemonClientFree(void *opaque) { @@ -1129,6 +1057,12 @@ int main(int argc, char **argv) { * scratch if rv =3D=3D 0 */ if (rv =3D=3D 0) { + VIR_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 }, + }; + if (godaemon) { char ebuf[1024]; =20 @@ -1156,31 +1090,46 @@ int main(int argc, char **argv) { goto cleanup; } =20 + if (virSystemdGetActivation(actmap, + ARRAY_CARDINALITY(actmap), + &act) < 0) { + ret =3D VIR_LOG_DAEMON_ERR_NETWORK; + goto cleanup; + } + logSrv =3D virNetDaemonGetServer(logDaemon->dmn, "virtlogd"); adminSrv =3D virNetDaemonGetServer(logDaemon->dmn, "admin"); - if ((rv =3D virLogDaemonSetupNetworkingSystemD(logSrv, adminSrv)) = < 0) { + + if (virNetServerAddServiceUNIX(logSrv, + act, "virtlogd.socket", + sock_file, 0700, 0, 0, + NULL, + false, 0, 1) < 0) { + ret =3D VIR_LOG_DAEMON_ERR_NETWORK; + goto cleanup; + } + if (virNetServerAddServiceUNIX(adminSrv, + act, "virtlogd-admin.socket", + admin_sock_file, 0700, 0, 0, + NULL, + false, 0, 1) < 0) { ret =3D VIR_LOG_DAEMON_ERR_NETWORK; goto cleanup; } =20 - /* Only do this, if systemd did not pass a FD */ - if (rv =3D=3D 0) { - if (virLogDaemonSetupNetworkingNative(logSrv, sock_file) < 0 || - virLogDaemonSetupNetworkingNative(adminSrv, admin_sock_fil= e) < 0) { - ret =3D VIR_LOG_DAEMON_ERR_NETWORK; - goto cleanup; - } + if (act && + virSystemdActivationComplete(act) < 0) { + ret =3D VIR_LOG_DAEMON_ERR_NETWORK; + goto cleanup; } - virObjectUnref(logSrv); - virObjectUnref(adminSrv); + } else { + logSrv =3D virNetDaemonGetServer(logDaemon->dmn, "virtlogd"); + /* If exec-restarting from old virtlogd, we won't have an + * admin server present */ + if (virNetDaemonHasServer(logDaemon->dmn, "admin")) + adminSrv =3D virNetDaemonGetServer(logDaemon->dmn, "admin"); } =20 - logSrv =3D virNetDaemonGetServer(logDaemon->dmn, "virtlogd"); - /* If exec-restarting from old virtlogd, we won't have an - * admin server present */ - if (virNetDaemonHasServer(logDaemon->dmn, "admin")) - adminSrv =3D virNetDaemonGetServer(logDaemon->dmn, "admin"); - if (timeout !=3D -1) { VIR_DEBUG("Registering shutdown timeout %d", timeout); virNetDaemonAutoShutdown(logDaemon->dmn, --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list