From nobody Wed Feb 11 13:03:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; envelope-from=libvir-list-bounces@redhat.com; helo=mx5-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) by mx.zohomail.com with SMTPS id 1487851035158336.8370061808139; Thu, 23 Feb 2017 03:57:15 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1NBs5MP040822; Thu, 23 Feb 2017 06:54:05 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1NBrCB0031824 for ; Thu, 23 Feb 2017 06:53:12 -0500 Received: from dnr.brq.redhat.com (dhcp129-180.brq.redhat.com [10.34.129.180]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1NBrBWX009079 for ; Thu, 23 Feb 2017 06:53:12 -0500 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Thu, 23 Feb 2017 12:53:06 +0100 Message-Id: <089f28d134187af4883000f9bf803dd0dc92aa24.1487850710.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/4] Unify checking for machine1 systemd service 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-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Both virSystemdTerminateMachine and virSystemdCreateMachine propagate the error to tell between a non-systemd system and a hard error. In virSystemdGetMachineNameByPID both are treated the same, but an error is ignored by the callers. Split out the checks into a separate function. --- src/util/virsystemd.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 7ec3eee..d7a4e78 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -182,6 +182,20 @@ virSystemdMakeMachineName(const char *drivername, return machinename; } =20 +/* -2 =3D machine1 is not supported on this machine + * -1 =3D error + * 0 =3D machine1 is available + */ +static int +virSystemdHasCreateMachine(void) +{ + int ret; + if ((ret =3D virDBusIsServiceEnabled("org.freedesktop.machine1")) < 0) + return ret; + + return virDBusIsServiceRegistered("org.freedesktop.systemd1"); +} + =20 char * virSystemdGetMachineNameByPID(pid_t pid) @@ -190,10 +204,7 @@ virSystemdGetMachineNameByPID(pid_t pid) DBusMessage *reply =3D NULL; char *name =3D NULL, *object =3D NULL; =20 - if (virDBusIsServiceEnabled("org.freedesktop.machine1") < 0) - goto cleanup; - - if (virDBusIsServiceRegistered("org.freedesktop.systemd1") < 0) + if (virSystemdHasCreateMachine() < 0) goto cleanup; =20 if (!(conn =3D virDBusGetSystemBus())) @@ -268,11 +279,7 @@ int virSystemdCreateMachine(const char *name, char *slicename =3D NULL; static int hasCreateWithNetwork =3D 1; =20 - ret =3D virDBusIsServiceEnabled("org.freedesktop.machine1"); - if (ret < 0) - return ret; - - if ((ret =3D virDBusIsServiceRegistered("org.freedesktop.systemd1")) <= 0) + if ((ret =3D virSystemdHasCreateMachine()) < 0) return ret; =20 if (!(conn =3D virDBusGetSystemBus())) @@ -434,11 +441,7 @@ int virSystemdTerminateMachine(const char *name) =20 memset(&error, 0, sizeof(error)); =20 - ret =3D virDBusIsServiceEnabled("org.freedesktop.machine1"); - if (ret < 0) - goto cleanup; - - if ((ret =3D virDBusIsServiceRegistered("org.freedesktop.systemd1")) <= 0) + if ((ret =3D virSystemdHasCreateMachine()) < 0) goto cleanup; =20 ret =3D -1; --=20 2.10.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list