From nobody Mon Feb 9 08:12:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1638543634; cv=none; d=zohomail.com; s=zohoarc; b=AoqIlW3rVKuggTm3bUDo36Amy+ZNhNbMx8lNfsa5GOPL3U6fcwOCIpjxO1NBECewJC01vr6W+Wl+3U6UHRDX9h5GCOLNFVg/fmyOKw5O04KCG5ik/2A2EGNGXHOVmavw915su/h6y5ul2uqARBUXvPmhg9gjHZj/yynTGK0r87A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638543634; 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=g2Rk7jPOIICdjrrTXzCoGLyeL0MLN9b459pprBENunM=; b=REsT/5HXfXYhrVwDparfSZmn1LEIkR//POBWC7KoM3S5FhHsqVFH0/cT+9VNsUXnju9rBMcmINIc5u1R/hjEDTt+qWS+du3PoW13DouLZGezn/lCTtwe7jXGAOwOq+w5NwzBkL6MWOiVdj6orA9dk+nRNkZE13/Pb95N2HRXKhE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1638543634079592.2630546258996; Fri, 3 Dec 2021 07:00:34 -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-552-_5I8LqvaMQS7RbA7nGPhtQ-1; Fri, 03 Dec 2021 10:00: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 9446285B664; Fri, 3 Dec 2021 15:00: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 6B4485F4E7; Fri, 3 Dec 2021 15:00:25 +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 C9DDE4BB7C; Fri, 3 Dec 2021 15:00:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B3Evp65029605 for ; Fri, 3 Dec 2021 09:57:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id BDA1E10016F5; Fri, 3 Dec 2021 14:57:51 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B8FB10016F4 for ; Fri, 3 Dec 2021 14:57:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638543633; 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=g2Rk7jPOIICdjrrTXzCoGLyeL0MLN9b459pprBENunM=; b=E1Yg79shvFw51VRiaj8/9XXGmMB4DfpmhTtrPypAkAL8rp4WfBTB+2dQ2GiPK2aAMsUdYl qHi+cxTA8AEeZOwKbPQ28B702NNWJTzvFEvKFqbPni1XV6jVgMrz8PfGJqOvZt+UMXpmRB a2Jf9ogUOTvYVch8IzVkuY8hcO2t3qU= X-MC-Unique: _5I8LqvaMQS7RbA7nGPhtQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/16] virLockDaemonPostExecRestart: Refactor cleanup Date: Fri, 3 Dec 2021 15:57:33 +0100 Message-Id: <0e45a964c494edb73c18ee160580233051e7c408.1638543041.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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) X-ZM-MESSAGEID: 1638543635716100001 Content-Type: text/plain; charset="utf-8" Move the unlinking of the state file earlier and get rid of the cleanup label. Signed-off-by: Peter Krempa --- src/locking/lock_daemon.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 1edd912c3e..107fb22bc2 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -608,59 +608,57 @@ virLockDaemonPostExecRestart(const char *state_file, { const char *gotmagic; g_autofree char *wantmagic =3D NULL; - int ret =3D -1; g_autofree char *state =3D NULL; g_autoptr(virJSONValue) object =3D NULL; + int rc; VIR_DEBUG("Running post-restart exec"); if (!virFileExists(state_file)) { VIR_DEBUG("No restart state file %s present", state_file); - ret =3D 0; - goto cleanup; + return 0; } - if (virFileReadAll(state_file, - 1024 * 1024 * 10, /* 10 MB */ - &state) < 0) - goto cleanup; + rc =3D virFileReadAll(state_file, + 1024 * 1024 * 10, /* 10 MB */ + &state); + + unlink(state_file); + + if (rc < 0) + return -1; VIR_DEBUG("Loading state %s", state); if (!(object =3D virJSONValueFromString(state))) - goto cleanup; + return -1; gotmagic =3D virJSONValueObjectGetString(object, "magic"); if (!gotmagic) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing magic data in JSON document")); - goto cleanup; + return -1; } if (!(wantmagic =3D virLockDaemonGetExecRestartMagic())) - goto cleanup; + return -1; if (STRNEQ(gotmagic, wantmagic)) { VIR_WARN("Found restart exec file with old magic %s vs wanted %s", gotmagic, wantmagic); - ret =3D 0; - goto cleanup; + return 0; } /* Re-claim PID file now as we will not be daemonizing */ if (pid_file && (*pid_file_fd =3D virPidFileAcquirePath(pid_file, false, getpid())= ) < 0) - goto cleanup; + return -1; if (!(lockDaemon =3D virLockDaemonNewPostExecRestart(object, privilege= d))) - goto cleanup; - - ret =3D 1; + return -1; - cleanup: - unlink(state_file); - return ret; + return 1; } --=20 2.31.1