zsh-workers
 help / color / mirror / code / Atom feed
From: Philippe Troin <phil+github-commits@fifi.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Cc: Philippe Troin <phil+github-commits@fifi.org>
Subject: [PATCH 2/3] Factorize the code that unlock the fcntl() lock into funlockhistfile().
Date: Fri,  8 Mar 2019 16:54:41 -0800	[thread overview]
Message-ID: <20190309005442.944477-2-phil+github-commits@fifi.org> (raw)
In-Reply-To: <20190309005442.944477-1-phil+github-commits@fifi.org>

---
 Src/hist.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/Src/hist.c b/Src/hist.c
index 4e1f24afe..981316674 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -2571,6 +2571,15 @@ flockhistfile(char *fn, int keep_trying)
 
     return 0;
 }
+
+static void
+funlockhistfile()
+{
+    if (flock_fd >= 0) {
+	close(flock_fd);
+	flock_fd = -1;
+    }
+}
 #endif
 
 /**/
@@ -2951,10 +2960,7 @@ savehistfile(char *fn, int err, int writeflags)
 		} else {
 		    /* We renamed over the locked HISTFILE, so close fd.
 		     * If we do more writing, we'll get a lock then. */
-		    if (flock_fd >= 0) {
-			close(flock_fd);
-			flock_fd = -1;
-		    }
+		    funlockhistfile();
 #endif
 		}
 	    }
@@ -3158,10 +3164,7 @@ lockhistfile(char *fn, int keep_trying)
 
     if (ct == lockhistct) {
 #ifdef HAVE_FCNTL_H
-	if (flock_fd >= 0) {
-	    close(flock_fd);
-	    flock_fd = -1;
-	}
+	funlockhistfile();
 #endif
 	DPUTS(ret == 0, "BUG: return value non-zero on locking error");
 	return ret;
@@ -3191,10 +3194,7 @@ unlockhistfile(char *fn)
 	unlink(lockfile);
 	free(lockfile);
 #ifdef HAVE_FCNTL_H
-	if (flock_fd >= 0) {
-	    close(flock_fd);
-	    flock_fd = -1;
-	}
+	funlockhistfile();
 #endif
     }
 }
-- 
2.20.1


  reply	other threads:[~2019-03-09  0:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-27 18:30 Issues with fcntl() history file locking Philippe Troin
2019-02-27 21:27 ` Bart Schaefer
2019-02-28  6:36   ` Philippe Troin
2019-03-09  0:53     ` Philippe Troin
2019-03-09  0:54       ` [PATCH 1/3] Move readhistfile() after flockhistfile() Philippe Troin
2019-03-09  0:54         ` Philippe Troin [this message]
2019-03-09  0:54         ` [PATCH 3/3] Delay closing the history file until the fcntl-lock is released Philippe Troin
     [not found]         ` <CAH+w=7aUD11M_GYy-FOC5MPGpGXb+o9O_q855OTC32fnSnpshQ@mail.gmail.com>
     [not found]           ` <82f4a6db638fbfce396e64a45029424185863068.camel@fifi.org>
     [not found]             ` <CAH+w=7ZS=ke8xHuBaO+hu0-RTtW=GYnG-0MENfBtTsyyp9joyg@mail.gmail.com>
     [not found]               ` <3228a3e68f2580fc25a9fda9bf7ccf5ce9a73689.camel@fifi.org>
2019-03-10  1:19                 ` [PATCH 1/3] Move readhistfile() after flockhistfile() Bart Schaefer
2019-03-11 21:04                   ` Jason L Tibbitts III
2019-03-12  7:55                     ` Jun T
2019-03-12  9:52                       ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190309005442.944477-2-phil+github-commits@fifi.org \
    --to=phil+github-commits@fifi.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).