diff options
author | 2021-10-02 21:43:05 -0400 | |
---|---|---|
committer | 2021-10-02 21:43:05 -0400 | |
commit | 6f6354f622ef92418cfd3f111064c37d4a6cd6c9 (patch) | |
tree | 6fa89ef6b34fcfbd73323f32675c2cdf0b0e3d6e | |
parent | switch to arrays (diff) | |
download | build-docbook-catalog-6f6354f622ef92418cfd3f111064c37d4a6cd6c9.tar.gz build-docbook-catalog-6f6354f622ef92418cfd3f111064c37d4a6cd6c9.tar.bz2 build-docbook-catalog-6f6354f622ef92418cfd3f111064c37d4a6cd6c9.zip |
switch locking to flock
If the tool gets killed while holding its lock, the files stay locked,
and future runs hang waiting for the lock, until a dev manually clears
things. Switch to flock as it provides a process-based lock and the
kernel will release it automatically when we exit.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rwxr-xr-x | build-docbook-catalog | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/build-docbook-catalog b/build-docbook-catalog index b815bfc..b4d7223 100755 --- a/build-docbook-catalog +++ b/build-docbook-catalog @@ -69,14 +69,11 @@ main() { mkdir -p "${ROOT}${ROOTCONFDIR}" || error "could not create ${ROOTCONFDIR}" fi - local lock="${ROOT}${ROOTCONFDIR}"/build-docbook-catalog-lock + local lock="${ROOT}/run/lock/build-docbook-catalog.lock" ( # Lock the dir to avoid trashing other runs that might # be running parallel. - touch "${lock}".$$ && \ - until ln "${lock}".$$ "${lock}" 2>/dev/null; do sleep 1; done && \ - rm "${lock}".$$ - [[ -f ${lock}.$$ ]] && error "unable to lock ${ROOTCONFDIR}" + flock 200 create_catalogs # will exit on error for type in xsl xsl-ns xsl-saxon xsl-xalan; do @@ -98,8 +95,9 @@ main() { populate_entities fi - ) - rm "${lock}" + # NB: Don't delete the lock since we can't delete files by fd, and if we do + # it by path, we might delete the lock while other processes grab it. + ) 200>>"${lock}" exit 0 } |