From patchwork Wed Nov 10 11:40:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 12611925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F34B3C433F5 for ; Wed, 10 Nov 2021 11:41:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D480B611BF for ; Wed, 10 Nov 2021 11:41:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231325AbhKJLoI (ORCPT ); Wed, 10 Nov 2021 06:44:08 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:59013 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230440AbhKJLoG (ORCPT ); Wed, 10 Nov 2021 06:44:06 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 6816F5C020F; Wed, 10 Nov 2021 06:41:18 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 10 Nov 2021 06:41:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=MShJwPBeKt0Sc41wjqCPpBdkteI dXABJdu8HFg3o2UI=; b=HDZ56wgIrPMc/d2xEc+hKNES9XjhQ+6cBikl36wJIqV MKC3rJIE9w/49vzzq12rvwQHLfwB7xOHP8QDG8+uJ+T8HyhpdDTyudCx5WJ2K67u 9TmVVN9cFan5Vju5ZijwX1V4cOU4LQBIDa3nQy+SAzU90b26NF7lic8gqtGT0bDZ kPRY55VzM6aqVbIg2A4gd41oWGOnA4Fchrdrb6Jgi3mGsessXqUs7xZRzQXmGpSi wlS69hvIQXnApyD9wji2keVYzBVQ0+fTFGjO73U7bgwPTR0Xr2wfbOVbq7XhuoAj DoifLQ3HqBqoWMQgCNKd4WUklgUAhgV9xfpv61fLJSA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=MShJwP BeKt0Sc41wjqCPpBdkteIdXABJdu8HFg3o2UI=; b=ZiMMw0QDLeIcstSvCCKmdS TwnRhAmZ0gqv8EN2ZnEWPyYP04JpbvzCiQ16hSA5rUCtVZ1vG4CzhseeQpp4dS6G jMgCetjx1KzkdrrW/0dz3gNmwIPOc+Qmq9O42aRleZaCfP6fSTOdzN0wag9wDCTp eXQt7QwSW8h+cuqECjcG0fhuRsUKY9jBuV4bMjAUbtSIDWeJSxA5odgBYkc8BY0I X50AQ0xcoz1L9QmP1wIXCnlRCN5MMUpaIT+oCC6cfBipqbghfX7eRZqa8X46LxfA w/Yjkw3b/otF4T6IucMh0BW3jigRdgv/CXWdUK6vxWambmbVK6TS70QgmlhkRocQ == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddrudejgdeftdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhrihgt khcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnh epheeghfdtfeeuffehkefgffduleffjedthfdvjeektdfhhedvlefgtefgvdettdfhnecu vehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkh hsrdhimh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 10 Nov 2021 06:41:17 -0500 (EST) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id ed12fa1f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 10 Nov 2021 13:26:27 +0000 (UTC) Date: Wed, 10 Nov 2021 12:40:54 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Johannes Schindelin , =?iso-8859-1?q?=C6var_Arn?= =?iso-8859-1?q?fj=F6r=F0?= Bjarmason , Junio C Hamano , Eric Wong , "Neeraj K. Singh" Subject: [PATCH v2 1/3] wrapper: handle EINTR in `git_fsync()` Message-ID: <0c8e98295e91b656a89e1db53bfe02e7c7fc8432.1636544377.git.ps@pks.im> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org While we already have a wrapper around `git_fsync()`, this wrapper doesn't handle looping around `EINTR`. Convert it to do so such that callers don't have to remember doing this everywhere. Signed-off-by: Patrick Steinhardt --- wrapper.c | 9 ++++++++- write-or-die.c | 6 ++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/wrapper.c b/wrapper.c index ece3d2ca10..e20df4f3a6 100644 --- a/wrapper.c +++ b/wrapper.c @@ -546,7 +546,7 @@ int xmkstemp_mode(char *filename_template, int mode) return fd; } -int git_fsync(int fd, enum fsync_action action) +static int git_fsync_once(int fd, enum fsync_action action) { switch (action) { case FSYNC_WRITEOUT_ONLY: @@ -591,7 +591,14 @@ int git_fsync(int fd, enum fsync_action action) default: BUG("unexpected git_fsync(%d) call", action); } +} +int git_fsync(int fd, enum fsync_action action) +{ + while (git_fsync_once(fd, action) < 0) + if (errno != EINTR) + return -1; + return 0; } static int warn_if_unremovable(const char *op, const char *file, int rc) diff --git a/write-or-die.c b/write-or-die.c index cc8291d979..e61220aa2d 100644 --- a/write-or-die.c +++ b/write-or-die.c @@ -57,10 +57,8 @@ void fprintf_or_die(FILE *f, const char *fmt, ...) void fsync_or_die(int fd, const char *msg) { - while (git_fsync(fd, FSYNC_HARDWARE_FLUSH) < 0) { - if (errno != EINTR) - die_errno("fsync error on '%s'", msg); - } + if (git_fsync(fd, FSYNC_HARDWARE_FLUSH) < 0) + die_errno("fsync error on '%s'", msg); } void write_or_die(int fd, const void *buf, size_t count)