From nobody Mon Feb 9 16:02:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1612877194; cv=none; d=zohomail.com; s=zohoarc; b=j7LNueg7UX0sPq7B6rrO/l22dkPJj20nJM49TpuX1SALj+imvpNxgYeUY+m2RSwWZTS0qqGHixCq8VT4/xNqnWR7KUcKFLfuz41psOQPArQ6uaKU1Bk5g+4+9ueEwT5nuToB00mcYylDTJHII7VbyqpUArL9deUtf0drmqxPOPk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612877194; 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; bh=YfI2L06V4wiB49NPdhNrJjM3FzZEP5M5LQafyg4AkLA=; b=PNz8GP/AB9Rp8aY1kyz04LnKhSsSxOLcwT90ClYGBD7cAfVT6GKmPemhJMd7DesSRzuhgfCW466qJWl+yS4LKtwM4FMLaE1RBa4emP+6/1bUYO8+lMupI11aPIeqLrXXVzfYONCeyjrGvVIhIbeG1rNZDnCCR1PNhSk6dp7lVco= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612877194416761.1379964940674; Tue, 9 Feb 2021 05:26:34 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-142-X6j7MkpJP0aM0qeqyxOppQ-1; Tue, 09 Feb 2021 08:26:31 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 53B8A1934106; Tue, 9 Feb 2021 13:26:25 +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 C4C115D736; Tue, 9 Feb 2021 13:26:24 +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 BF9C7A6EE; Tue, 9 Feb 2021 13:26:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 119DQLt8020399 for ; Tue, 9 Feb 2021 08:26:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id C8E885D9CD; Tue, 9 Feb 2021 13:26:21 +0000 (UTC) Received: from antique-laptop.redhat.com (unknown [10.40.208.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3104F5D9C0 for ; Tue, 9 Feb 2021 13:26:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612877193; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=YfI2L06V4wiB49NPdhNrJjM3FzZEP5M5LQafyg4AkLA=; b=H1G8JQj+dSJ+Lo5XjmJ0DQ2kiniQxfydHrPJzslkLv7/Sx/9zO2xXOK9B8of5ru6hUla7a Rz74TJoFTw2r5hQZM3SaC4pn+jISpstZAxC+OwA534U6NM0RR9VT1OV1SlbhfUwY/RQ7SP dn+y0+/j7+g/i9+uZ9myUBvJNzUp5qo= X-MC-Unique: X6j7MkpJP0aM0qeqyxOppQ-1 From: Pavel Hrdina To: libvir-list@redhat.com Subject: [libvirt PATCH 2/9] virsystemd: introduce virSystemdGetMachineByPID Date: Tue, 9 Feb 2021 14:26:07 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.15 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/virsystemd.c | 52 ++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 58b5c650b5..d2fcf0bf0c 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -194,21 +194,21 @@ virSystemdHasLogind(void) } =20 =20 -char * -virSystemdGetMachineNameByPID(pid_t pid) +/** + * virSystemdGetMachineByPID: + * @conn: dbus connection + * @pid: pid of running VM + * + * Returns dbus object path to VM registered with machined. + * On error returns NULL. + */ +static char * +virSystemdGetMachineByPID(GDBusConnection *conn, + pid_t pid) { - GDBusConnection *conn; g_autoptr(GVariant) message =3D NULL; g_autoptr(GVariant) reply =3D NULL; - g_autoptr(GVariant) gvar =3D NULL; - g_autofree char *object =3D NULL; - char *name =3D NULL; - - if (virSystemdHasMachined() < 0) - return NULL; - - if (!(conn =3D virGDBusGetSystemBus())) - return NULL; + char *object =3D NULL; =20 message =3D g_variant_new("(u)", pid); =20 @@ -225,13 +225,33 @@ virSystemdGetMachineNameByPID(pid_t pid) =20 g_variant_get(reply, "(o)", &object); =20 - g_variant_unref(reply); - reply =3D NULL; - VIR_DEBUG("Domain with pid %lld has object path '%s'", (long long) pid, object); =20 - g_variant_unref(message); + return object; +} + + +char * +virSystemdGetMachineNameByPID(pid_t pid) +{ + GDBusConnection *conn; + g_autoptr(GVariant) message =3D NULL; + g_autoptr(GVariant) reply =3D NULL; + g_autoptr(GVariant) gvar =3D NULL; + g_autofree char *object =3D NULL; + char *name =3D NULL; + + if (virSystemdHasMachined() < 0) + return NULL; + + if (!(conn =3D virGDBusGetSystemBus())) + return NULL; + + object =3D virSystemdGetMachineByPID(conn, pid); + if (!object) + return NULL; + message =3D g_variant_new("(ss)", "org.freedesktop.machine1.Machine", "Name"); =20 --=20 2.29.2