chiark
/
gitweb
/
~mdw
/
misc
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
80d6051
)
locking.c: Explain why the code has an apparently pointless `stat' call.
author
Mark Wooding
<mdw@distorted.org.uk>
Fri, 13 Sep 2019 21:09:32 +0000
(22:09 +0100)
committer
Mark Wooding
<mdw@distorted.org.uk>
Fri, 13 Sep 2019 21:09:32 +0000
(22:09 +0100)
locking.c
patch
|
blob
|
blame
|
history
diff --git
a/locking.c
b/locking.c
index bfc5c771927e13d04703108224992ce92aef6933..6317b2e619888bd7c276f1c4d28aea4dfd7ee827 100644
(file)
--- a/
locking.c
+++ b/
locking.c
@@
-192,6
+192,13
@@
again:
if (fstat(fd, &st))
die(111, "error from fstat on `%s': %s", file, strerror(errno));
err = fcntl(fd, f & f_wait ? F_SETLKW : F_SETLK, &l) >= 0 ? 0 : errno;
if (fstat(fd, &st))
die(111, "error from fstat on `%s': %s", file, strerror(errno));
err = fcntl(fd, f & f_wait ? F_SETLKW : F_SETLK, &l) >= 0 ? 0 : errno;
+ /* It's tempting to `optimize' this code by opening a new file descriptor
+ * here so as to elide the additional call to fstat(2) above. But this
+ * doesn't work: if we successfully acquire the lock, we then have two file
+ * descriptors open on the lock file, so we have to close one -- but, under
+ * the daft fcntl(2) rules, even closing `nfd' will release the lock
+ * immediately.
+ */
if (stat(file, &nst)) {
if (errno == ENOENT) { close(fd); goto again; }
else die(111, "error from stat on `%s': %s", file, strerror(errno));
if (stat(file, &nst)) {
if (errno == ENOENT) { close(fd); goto again; }
else die(111, "error from stat on `%s': %s", file, strerror(errno));