From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202606 header.b=lZXn8jZr; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id D67125A026D for ; Fri, 17 Jul 2026 07:46:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1784267197; bh=VZ77wZA2/svQtQ1xsQVTx/46a9yfLNVXAHpuBNDaJVI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lZXn8jZrjxzeMrL/8lZtyFZdDq/FikgSrPUigfGCzgfaRFhWYNZReG9t1LazzPLNa CjzLK1Dg5wNB6R/cEFL4C+thjutF430KuWccMFzo0H9q/XQYnxRynZJ97fc7zwUBA9 a7Gtu7oFnDX6xUUZzIAvKZ0febpV5KldMPWexW8vpC/7fYrbWsaIGXssBwBv2w6nRj 45sWLy6pICpaJ8g9w3L6IBrGTKc5U8lT46A+SXum6DC6IlA65uYokIS5yxxN9tbsLO RuBmHhwy7BBfrob5nwNkYrRi6cSJ+4MAwbxcqcCdWmgoNxBSjFasj0D+qKvHy15H0L dwRPxCmdg4F/Q== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4h1f6j076Rz4wB7; Fri, 17 Jul 2026 15:46:37 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 1/6] passt: Always close pidfile_fd, not just when daemonizing Date: Fri, 17 Jul 2026 15:46:29 +1000 Message-ID: <20260717054634.1293553-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260717054634.1293553-1-david@gibson.dropbear.id.au> References: <20260717054634.1293553-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: TXN5DBP7VQXH37VUAOQ4O75F2KJIM7SK X-Message-ID-Hash: TXN5DBP7VQXH37VUAOQ4O75F2KJIM7SK X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson , Jon Maloy X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: In order to satisfy static checkers that we don't have an fd leak, a9c61ffaf153 added a close() of c->pidfile_fd, amongst others. However, it only close()s it in the case where we daemonize into the background. While less universally useful in the foreground / non-daemon case, it's perfectly reasonable to still have a pidfile. We'll still write it, and we should still close it. Cc: Jon Maloy Fixes: a9c61ffaf153 ("util, passt: Close daemon-lifetime fds on exit to avoid Coverity warning") Signed-off-by: David Gibson --- passt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/passt.c b/passt.c index 65a07d72..cc847ec2 100644 --- a/passt.c +++ b/passt.c @@ -420,11 +420,13 @@ int main(int argc, char **argv) if (!c->foreground) { __daemon(c->pidfile_fd, devnull_fd); - close(c->pidfile_fd); - c->pidfile_fd = -1; log_stderr = false; } else { pidfile_write(c->pidfile_fd, getpid()); + } + + if (c->pidfile_fd >= 0) { + close(c->pidfile_fd); c->pidfile_fd = -1; } -- 2.55.0