From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id 8HQxMho7lma2TQAAe85BDQ:P1 (envelope-from ) for ; Tue, 16 Jul 2024 09:19:23 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id 8HQxMho7lma2TQAAe85BDQ (envelope-from ) for ; Tue, 16 Jul 2024 11:19:22 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=TMxYjNXV; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1721121562; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=zymSuu05wUsaPkj+VZXqKU0K5ZcilZM+hbGBPPkqzNs=; b=gdO0fmbJiKXbWCNe1Y4sUW6XcC3Hz85Qn3wQRRtcLZ96nyKTya7eRqrHm4Qt69Nj4N2l3w iaVBfvi3KGFQtvOGmrUWzSaRsI6ulBxTOsKDzN+uI0mSysdynBRIbO0i94mDDDdtDoLGyW vjjynTAx/nuGhPM48GdfAHFOWjnXFUl66g9p5tHeQ8+vQAYeBS4OjeRLNULc81h0jO+Lxf plNYyHjbyHpOkgYlgAfiEqTh1OItqg3UfoyxDa2u2OH/2WCvRxg3yYhltbDNDj0trYQUz9 Z6A7+t1su/re0egHVjbaS5YzpgkXWVwdeuzwdXmMdOnXF7BeEkZmqOMlNkD4jw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=TMxYjNXV; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1721121562; a=rsa-sha256; cv=none; b=nryMiA9Cz/+SLg3A4shr8oA7+HGmpfiniBLQIJBlsEdKQm9vh4owhkRzouKANk5MT/h2LR uity/zuJF1uKAng0ZENIfMJekql63T4cFsk9tKJZ8rt2H3q4wILUeOLAm4AiOt73Yhh2b2 4S/g9zCWwATmE+Aq3LToY03NAKu735+Qw4ACXqF+7eIUlypLQoMQ7aD94KoMBSADA8UnFk tA5LYFnuMzrtngt2xu9tTgKqp78PFJdiJ4QNk4s93ttZ25sQJrSlAEpayYCFOF2HwF+fQU JJUEGQSGqJvegnPy7WtuKJnOtvhLwQ7HGgbQZwzujW6nl5ss5bNVZ93yboSJQA== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A8B937E696 for ; Tue, 16 Jul 2024 11:19:22 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sTeKy-0003Cj-2G; Tue, 16 Jul 2024 05:19:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sTeKp-0003AR-Qx for guix-patches@gnu.org; Tue, 16 Jul 2024 05:18:59 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sTeKp-0003oe-Gs for guix-patches@gnu.org; Tue, 16 Jul 2024 05:18:59 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sTeKr-000548-OZ for guix-patches@gnu.org; Tue, 16 Jul 2024 05:19:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#72137] [PATCH 1/2] syscalls: Add =?UTF-8?Q?=E2=80=98mode=E2=80=99?= parameter to =?UTF-8?Q?=E2=80=98lock-file=E2=80=99.?= Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 16 Jul 2024 09:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72137 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 72137@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 72137-submit@debbugs.gnu.org id=B72137.172112149519386 (code B ref 72137); Tue, 16 Jul 2024 09:19:01 +0000 Received: (at 72137) by debbugs.gnu.org; 16 Jul 2024 09:18:15 +0000 Received: from localhost ([127.0.0.1]:60968 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sTeK0-00052O-1w for submit@debbugs.gnu.org; Tue, 16 Jul 2024 05:18:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53248) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sTeJx-00051p-Pa for 72137@debbugs.gnu.org; Tue, 16 Jul 2024 05:18:06 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sTeHk-0003TP-I9; Tue, 16 Jul 2024 05:15:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=zymSuu05wUsaPkj+VZXqKU0K5ZcilZM+hbGBPPkqzNs=; b=TMxYjNXVaiIV/YSijzSU sbh6GesukxRXJILCCmwg4LXkOHnamS2s20gifJAJAWwIpYnONOrsSsczXBc/Y82tswD+4aUJgxJbA Kqx5aWfWErGuenxL5M6TCnQxXieq/dwJJv8JUZUTsgufWUnRG6lE1AdXcoNZiPUdE9DNQE6D7RNl3 C5QofR9Fn0XhdtLBgZHODp5oLv07gpUl3kbVIya58LZ9+OA2NSxlbWga4vXLyuwWvnWfBqMeLtBXc oky+u2fTskgLxis2SVw8k9Jfs42wqHWYrvVWmITca/qg9RsGDPmgSOoO5SruJN6MPgFW6gZoPxf9Y RaT0eIEJL+y5hA==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Tue, 16 Jul 2024 11:15:36 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Spam-Score: -6.30 X-Migadu-Queue-Id: A8B937E696 X-Migadu-Scanner: mx10.migadu.com X-Migadu-Spam-Score: -6.30 X-TUID: mvZqiH0S9Pm5 * guix/build/syscalls.scm (lock-file): Add ‘mode’ parameter and honor it. * tests/syscalls.scm ("lock-file + unlock-file"): New test. Change-Id: I113fb4a8b35dd8782b9c0991574e39a4b4393333 --- guix/build/syscalls.scm | 14 +++++++++----- tests/syscalls.scm | 13 +++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index 39bcffd516..2c20edf058 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -1398,14 +1398,18 @@ (define fcntl-flock ;; Presumably we got EAGAIN or so. (throw 'flock-error err)))))) -(define* (lock-file file #:key (wait? #t)) - "Wait and acquire an exclusive lock on FILE. Return an open port." - (let ((port (open-file file "w0"))) - (fcntl-flock port 'write-lock #:wait? wait?) +(define* (lock-file file #:optional (mode "w0") + #:key (wait? #t)) + "Wait and acquire an exclusive lock on FILE. Return an open port according +to MODE." + (let ((port (open-file file mode))) + (fcntl-flock port + (if (output-port? port) 'write-lock 'read-lock) + #:wait? wait?) port)) (define (unlock-file port) - "Unlock PORT, a port returned by 'lock-file'." + "Unlock PORT, a port returned by 'lock-file', and close it." (fcntl-flock port 'unlock) (close-port port) #t) diff --git a/tests/syscalls.scm b/tests/syscalls.scm index 7cf67c060d..13f4f11721 100644 --- a/tests/syscalls.scm +++ b/tests/syscalls.scm @@ -383,6 +383,19 @@ (define perform-container-tests? (close-port file) result))))))))) +(test-equal "lock-file + unlock-file" + 'hello + (call-with-temporary-directory + (lambda (directory) + (let* ((file (in-vicinity directory "lock")) + (out (lock-file file #:wait? #f))) + (display "hello" out) + (unlock-file out) + (let* ((in (lock-file file "r0")) + (content (read in))) + (unlock-file in) + content))))) + (test-equal "set-thread-name" "Syscall Test" (let ((name (thread-name))) -- 2.45.2