From d1a7515f428e5b496a38cea6a887dd27dd9f1298 Mon Sep 17 00:00:00 2001 From: Johannes Matheis Date: Thu, 8 Apr 2021 12:08:03 +0000 Subject: [PATCH] use flock for stale lock file handling --- dehydrated | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dehydrated b/dehydrated index 27f930f6..70e9ca43 100755 --- a/dehydrated +++ b/dehydrated @@ -536,7 +536,9 @@ init_system() { if [[ -n "${LOCKFILE}" ]]; then LOCKDIR="$(dirname "${LOCKFILE}")" [[ -w "${LOCKDIR}" ]] || _exiterr "Directory ${LOCKDIR} for LOCKFILE ${LOCKFILE} is not writable, aborting." - ( set -C; date > "${LOCKFILE}" ) 2>/dev/null || _exiterr "Lock file '${LOCKFILE}' present, aborting." + exec 100>>"${LOCKFILE}" + flock -n 100 || _exiterr "Lock file '${LOCKFILE}' is locked, aborting." + date >"${LOCKFILE}" # for backward compability. Unreliable, since $LOCKFILE can exist after crash/SIGKILL remove_lock() { rm -f "${LOCKFILE}"; } trap 'remove_lock' EXIT fi