From patchwork Tue Nov 21 07:04:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13462548 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="gd3Wf6j9"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="nNQHRLdH" Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C360AF4 for ; Mon, 20 Nov 2023 23:04:21 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 39DF25C1575; Tue, 21 Nov 2023 02:04:21 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 21 Nov 2023 02:04:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1700550261; x=1700636661; bh=rn INZel+ZAkidiH5ybksGw1A/zgbtkxUHLUMfClGedM=; b=gd3Wf6j9ppocwiudOz vpsBvHkX/2gOWa/cm8ZynPEmD2MNUnyc8ZmTEXfZtlAE+Dfl/9pssm6trB9+82OH NwdeSgZ189trE2Jg4nxf13UbiJ52I+HFZTc6hZdm4hBTNX0HYvFdswbFGxcRclHu /9LGptX0bYAiwkRxUlvuRKlWRWKIXZTgbUei1/avPI51QeCepzzrw1ymostFHq/x xYOyabbzCiYIzPU/WqGOX5tr9NPYwTz2l1v9v04NvElfWOV5FsQ0+j4W/fPDkmcY dj1oXVSI5vLWAIzhfBY8WtxPYv0k9HZSy4bT75h8NqTrmWjkGmbJHdAQHdSCJbVZ 0aJw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1700550261; x=1700636661; bh=rnINZel+ZAkid iH5ybksGw1A/zgbtkxUHLUMfClGedM=; b=nNQHRLdHu9heU3mQB8uu5YSRZkv75 ezqF3+CCAlPIETyYZCTCddkEwUJs5fZC5lfngtIw9u998YFggP0HXWIoavvRoBRr Pl2yaQBfsfJ7zA/na+omhk+iA/TALAn2S5zbNes5ZiFlAoREyM+Nr/SozdGVkMUY y8TN0BfEhThlVME3gaknr+bTm0iVzj0dZDjI6OK6Do5Q22YeuYckujVNWRXZOTUD lEha90s2DJ1QobLm6Mnja8fDtCKJIPnLJ46AOxnQ/3XuvGmSUtvdXvrRmm4kH+Bt jzQrhwT4370NIZU3xHW4S5Tzoj8T4ppa5SnEa+HUYfzyY+Y8Bq+Dv4JTw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudegkedguddtfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 21 Nov 2023 02:04:20 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4f90c186 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 21 Nov 2023 07:03:28 +0000 (UTC) Date: Tue, 21 Nov 2023 08:04:18 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Jonathan Nieder Subject: [PATCH 3/8] reftable: handle interrupted writes Message-ID: <3c14f67c441251d7467757706715ca6d9a4be7c0.1700549493.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: There are calls to write(3P) where we don't properly handle interrupts. Convert them to use `write_in_full()`. Signed-off-by: Patrick Steinhardt --- reftable/stack.c | 6 +++--- reftable/stack_test.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/reftable/stack.c b/reftable/stack.c index ed108a929b..f0cadad490 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -42,7 +42,7 @@ static void stack_filename(struct strbuf *dest, struct reftable_stack *st, static ssize_t reftable_fd_write(void *arg, const void *data, size_t sz) { int *fdp = (int *)arg; - return write(*fdp, data, sz); + return write_in_full(*fdp, data, sz); } int reftable_new_stack(struct reftable_stack **dest, const char *dir, @@ -554,7 +554,7 @@ int reftable_addition_commit(struct reftable_addition *add) strbuf_addstr(&table_list, "\n"); } - err = write(add->lock_file_fd, table_list.buf, table_list.len); + err = write_in_full(add->lock_file_fd, table_list.buf, table_list.len); strbuf_release(&table_list); if (err < 0) { err = REFTABLE_IO_ERROR; @@ -1024,7 +1024,7 @@ static int stack_compact_range(struct reftable_stack *st, int first, int last, strbuf_addstr(&ref_list_contents, "\n"); } - err = write(lock_file_fd, ref_list_contents.buf, ref_list_contents.len); + err = write_in_full(lock_file_fd, ref_list_contents.buf, ref_list_contents.len); if (err < 0) { err = REFTABLE_IO_ERROR; unlink(new_table_path.buf); diff --git a/reftable/stack_test.c b/reftable/stack_test.c index d0b717510f..0644c8ad2e 100644 --- a/reftable/stack_test.c +++ b/reftable/stack_test.c @@ -78,7 +78,7 @@ static void test_read_file(void) int i = 0; EXPECT(fd > 0); - n = write(fd, out, strlen(out)); + n = write_in_full(fd, out, strlen(out)); EXPECT(n == strlen(out)); err = close(fd); EXPECT(err >= 0);