From nobody Sat Feb 7 08:28:04 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=suse.de Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1642078039065865.4873438791268; Thu, 13 Jan 2022 04:47:19 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-557-7JBqZuldO7OT-8zQR_hkXg-1; Thu, 13 Jan 2022 07:47:16 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 49A011023F4D; Thu, 13 Jan 2022 12:47:11 +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 2B13D60C49; Thu, 13 Jan 2022 12:47:11 +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 EC64E4A7C9; Thu, 13 Jan 2022 12:47:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 20DCgv4r009453 for ; Thu, 13 Jan 2022 07:42:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id B6F86C080AD; Thu, 13 Jan 2022 12:42:57 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B2A5CC0809E for ; Thu, 13 Jan 2022 12:42:57 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 987AA801E95 for ; Thu, 13 Jan 2022 12:42:57 +0000 (UTC) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-647-qJthMNFePzGrT1FU7UQ8Og-1; Thu, 13 Jan 2022 07:42:55 -0500 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D375E21129; Thu, 13 Jan 2022 12:42:54 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A3F4C13BF7; Thu, 13 Jan 2022 12:42:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EFNiJk4e4GG0SQAAMHmgww (envelope-from ); Thu, 13 Jan 2022 12:42:54 +0000 X-MC-Unique: 7JBqZuldO7OT-8zQR_hkXg-1 X-MC-Unique: qJthMNFePzGrT1FU7UQ8Og-1 From: Vasiliy Ulyanov To: libvir-list@redhat.com Subject: [PATCH v2 2/4] virpidfile: Refactor virPidFileReadPathIfAlive Date: Thu, 13 Jan 2022 13:42:36 +0100 Message-Id: <20220113124238.2279-3-vulyanov@suse.de> In-Reply-To: <20220113124238.2279-1-vulyanov@suse.de> References: <20220113124238.2279-1-vulyanov@suse.de> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 20DCgv4r009453 X-loop: libvir-list@redhat.com Cc: Vasiliy Ulyanov 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.14 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-ZM-MESSAGEID: 1642078039812100001 Content-Type: text/plain; charset="utf-8" If the binary path is not provided check that the pid file is locked by the owner process. Signed-off-by: Vasiliy Ulyanov --- src/util/virpidfile.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index 7069f8343d..8ddc336d6c 100644 --- a/src/util/virpidfile.c +++ b/src/util/virpidfile.c @@ -216,6 +216,26 @@ int virPidFileReadPathIfAlive(const char *path, #endif =20 if (!binPath) { + int fd; + pid_t ownerPid; + + if ((fd =3D open(path, O_RDONLY)) < 0) + return -1; + + if (virFileGetLockOwner(fd, 0, 1, &ownerPid) < 0) { + VIR_FORCE_CLOSE(fd); + return -1; + } + + if (VIR_CLOSE(fd) < 0) + return -1; + + /* A pid file should be locked by the process owning it. */ + if (ownerPid !=3D retPid) { + *pid =3D -1; + return 0; + } + /* we only knew the pid, and that pid is alive, so we can * return it. */ --=20 2.34.1