From nobody Thu Dec 18 14:54:42 2025 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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=1678206845; cv=none; d=zohomail.com; s=zohoarc; b=OqSWzXD+LIyLGj/LNQLctGd9LXtMRheT3pXkhAX2p/eFIWjVkYa+r/Ezlqgwb2yLkXZzCMFOe+gIWvAWRw3vCtKhJ7HQ1VhH7/8hcbtqX+AJiK6fk/MDPbuIe2LKX+QJYcMSe4r4nTWzPBsbA2VrVWqHImhsJt/QvMGBhZXkoQA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678206845; 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=SRRlTOMal4/vEIaih2rI0uith7/IBNFZQcDqVkkBc2M=; b=ETT5f4l1L78qqAEPTk974RECoLuQfC1/uQ3cNvN0jxJCdzqv4zoIld0GXpJFE9sBDn2tOjf5H1/MdvrHLPD+c1BcCIy9V7qTnpsn3bIkYtcfAZxVKDf9d/GDpjvLjsTLE0cjXMtf74+2TfZ8dP1HoeayUXeHPglh2Bm4VA3QBH0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1678206845831827.2373207929248; Tue, 7 Mar 2023 08:34:05 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-161-sDx2ZLznPiSzhh4NktICdA-1; Tue, 07 Mar 2023 11:29:53 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8E8481C2C4F4; Tue, 7 Mar 2023 16:16:09 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7586AC16025; Tue, 7 Mar 2023 16:16:09 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 625B419465B8; Tue, 7 Mar 2023 16:16:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id EC12619465B6 for ; Tue, 7 Mar 2023 16:16:06 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E0AD31401C32; Tue, 7 Mar 2023 16:16:06 +0000 (UTC) Received: from fedora.. (unknown [10.43.2.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8957E1402641 for ; Tue, 7 Mar 2023 16:16:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678206843; 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=SRRlTOMal4/vEIaih2rI0uith7/IBNFZQcDqVkkBc2M=; b=d90qTqFSU7Myn4nV0StRXQYI+WVZiivbG13rg0ypnBW40Nz6krXCLse9ucVE6+OsYiijUp VaOC+Mb3kk8Whg3anPRq+A2dBjCGTwdcWYrPeglPwxr5SqlQtt3uvPz2OzCTboxyNNazJD nXfT671HL77iSEj+/x6IDk5qMdYbgbg= X-MC-Unique: sDx2ZLznPiSzhh4NktICdA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 5/6] util: add quiet parameter to virPidFileAcquirePathFull Date: Tue, 7 Mar 2023 17:16:01 +0100 Message-Id: <879d4a7bcb97b4fe84fc3399f8d767f68b285f42.1678205730.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1678206846295100001 Signed-off-by: J=C3=A1n Tomko --- src/network/leaseshelper.c | 2 +- src/util/virpidfile.c | 51 ++++++++++++++++++++++++-------------- src/util/virpidfile.h | 1 + 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c index b1ce313e6a..9ee42045d9 100644 --- a/src/network/leaseshelper.c +++ b/src/network/leaseshelper.c @@ -159,7 +159,7 @@ main(int argc, char **argv) pid_file =3D g_strdup(RUNSTATEDIR "/leaseshelper.pid"); =20 /* Try to claim the pidfile, exiting if we can't */ - if ((pid_file_fd =3D virPidFileAcquirePathFull(pid_file, true, getpid(= ))) < 0) { + if ((pid_file_fd =3D virPidFileAcquirePathFull(pid_file, true, false, = getpid())) < 0) { fprintf(stderr, _("Unable to acquire PID file: %s\n errno=3D%d"), pid_file, errno); diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index 252100cdc3..05d19100c6 100644 --- a/src/util/virpidfile.c +++ b/src/util/virpidfile.c @@ -364,6 +364,7 @@ int virPidFileDelete(const char *dir, =20 int virPidFileAcquirePathFull(const char *path, bool waitForLock, + bool quiet, pid_t pid) { int fd =3D -1; @@ -375,32 +376,40 @@ int virPidFileAcquirePathFull(const char *path, while (1) { struct stat a, b; if ((fd =3D open(path, O_WRONLY|O_CREAT, 0644)) < 0) { - virReportSystemError(errno, - _("Failed to open pid file '%s'"), - path); + if (!quiet) { + virReportSystemError(errno, + _("Failed to open pid file '%s'"), + path); + } return -1; } =20 if (virSetCloseExec(fd) < 0) { - virReportSystemError(errno, - _("Failed to set close-on-exec flag '%s'"= ), - path); + if (!quiet) { + virReportSystemError(errno, + _("Failed to set close-on-exec flag '= %s'"), + path); + } VIR_FORCE_CLOSE(fd); return -1; } =20 if (fstat(fd, &b) < 0) { - virReportSystemError(errno, - _("Unable to check status of pid file '%s= '"), - path); + if (!quiet) { + virReportSystemError(errno, + _("Unable to check status of pid file= '%s'"), + path); + } VIR_FORCE_CLOSE(fd); return -1; } =20 if (virFileLock(fd, false, 0, 1, waitForLock) < 0) { - virReportSystemError(errno, - _("Failed to acquire pid file '%s'"), - path); + if (!quiet) { + virReportSystemError(errno, + _("Failed to acquire pid file '%s'"), + path); + } VIR_FORCE_CLOSE(fd); return -1; } @@ -427,17 +436,21 @@ int virPidFileAcquirePathFull(const char *path, g_snprintf(pidstr, sizeof(pidstr), "%lld", (long long) pid); =20 if (ftruncate(fd, 0) < 0) { - virReportSystemError(errno, - _("Failed to truncate pid file '%s'"), - path); + if (!quiet) { + virReportSystemError(errno, + _("Failed to truncate pid file '%s'"), + path); + } VIR_FORCE_CLOSE(fd); return -1; } =20 if (safewrite(fd, pidstr, strlen(pidstr)) < 0) { - virReportSystemError(errno, - _("Failed to write to pid file '%s'"), - path); + if (!quiet) { + virReportSystemError(errno, + _("Failed to write to pid file '%s'"), + path); + } VIR_FORCE_CLOSE(fd); } =20 @@ -448,7 +461,7 @@ int virPidFileAcquirePathFull(const char *path, int virPidFileAcquirePath(const char *path, pid_t pid) { - return virPidFileAcquirePathFull(path, false, pid); + return virPidFileAcquirePathFull(path, false, false, pid); } =20 =20 diff --git a/src/util/virpidfile.h b/src/util/virpidfile.h index 6db0fb843f..5d31f02702 100644 --- a/src/util/virpidfile.h +++ b/src/util/virpidfile.h @@ -58,6 +58,7 @@ int virPidFileDelete(const char *dir, =20 int virPidFileAcquirePathFull(const char *path, bool waitForLock, + bool quiet, pid_t pid) G_GNUC_WARN_UNUSED_RESULT; int virPidFileAcquirePath(const char *path, pid_t pid) G_GNUC_WARN_UNUSED_RESULT; --=20 2.39.2