diff options
author | rillig <rillig> | 2007-02-20 22:11:10 +0000 |
---|---|---|
committer | rillig <rillig> | 2007-02-20 22:11:10 +0000 |
commit | e28871eb7ba01001cd3d8621a198ad35caac03bf (patch) | |
tree | 02479c7b31cd2d43dcc64032ee07e3f76addbc5c | |
parent | a598d4c664316d16bac16de685c89d7eefc89a22 (diff) | |
download | pkgsrc-e28871eb7ba01001cd3d8621a198ad35caac03bf.tar.gz |
Made the locking more flexible by letting the user choose different
locking types for WRKDIR and LOCALBASE.
The default values are currently based on PKGSRC_LOCKTYPE, but the
recommended values are different. For LOCALBASE, the recommended value
is "sleep", since after one transaction has finished, the next can be
done in the new LOCALBASE without problems.
The situation is different though in WRKDIR. After one transaction has
finished there, it is often the case that the directory is removed,
including the lockfile. In that case, the package has usually been
installed and packaged successfully, and it would be a bad idea to let
the next transaction try to do the same again. Therefore, the
recommended value here is "once".
-rw-r--r-- | mk/internal/locking.mk | 102 |
1 files changed, 66 insertions, 36 deletions
diff --git a/mk/internal/locking.mk b/mk/internal/locking.mk index b530ba3efff..dff0abe4b4d 100644 --- a/mk/internal/locking.mk +++ b/mk/internal/locking.mk @@ -1,6 +1,21 @@ -# $NetBSD: locking.mk,v 1.5 2007/02/19 10:39:47 rillig Exp $ +# $NetBSD: locking.mk,v 1.6 2007/02/20 22:11:10 rillig Exp $ +# +# User-settable variables: +# +# WRKDIR_LOCKTYPE +# The type of locking used for WRKDIR. +# +# Possible values: none once sleep +# Default value: none +# Recommended: once +# +# LOCALBASE_LOCKTYPE +# The type of locking used for LOCALBASE. +# +# Possible values: none once sleep +# Default value: none +# Recommended: sleep # - # This file provides the following .USE targets: # # acquire-lock @@ -16,34 +31,41 @@ # Releases the lock in LOCALBASE. # +WRKDIR_LOCKTYPE?= ${PKGSRC_LOCKTYPE} +LOCALBASE_LOCKTYPE?= ${PKGSRC_LOCKTYPE} + _WRKDIR_LOCKFILE= ${WRKDIR}/.lockfile _LOCALBASE_LOCKFILE= ${LOCALBASE}/.lockfile +_LOCKVARS= WRKDIR_LOCKTYPE LOCALBASE_LOCKTYPE # # Sanity checks. # -.if ${PKGSRC_LOCKTYPE} == "none" -# No further checks. -.elif ${PKGSRC_LOCKTYPE} == "once" || ${PKGSRC_LOCKTYPE} == "sleep" -. if !defined(OBJHOSTNAME) -PKG_FAIL_REASON+= "[locking.mk] PKGSRC_LOCKTYPE needs OBJHOSTNAME defined." -# XXX: Why? +.for v in ${_LOCKVARS} +_OK= no +. for t in none once sleep +. if ${PKGSRC_LOCKTYPE} == "${t}" +_OK= yes +. endif +. endfor +. if ${_OK} != "yes" +PKG_FAIL_REASON+= "[locking.mk] ${v} must be one of { none once sleep }, not ${${v}}." . endif -.else -PKG_FAIL_REASON+= "[locking.mk] PKGSRC_LOCKTYPE must be one of {none,once,sleep}, not ${PKGSRC_LOCKTYPE}." -.endif +.endfor # # Needed tools. # -.if ${PKGSRC_LOCKTYPE} != "none" +.for v in ${_LOCKVARS} +. if ${${v}} != "none" USE_TOOLS+= shlock -.endif -.if ${PKGSRC_LOCKTYPE} == "sleep" +. endif +. if ${${v}} == "sleep" USE_TOOLS+= sleep -.endif +. endif +.endfor # # The commands. @@ -59,14 +81,14 @@ _CHECK_IF_SHLOCK_IS_AVAILABLE_CMD= \ _ACQUIRE_LOCK_CMD= \ ${_CHECK_IF_SHLOCK_IS_AVAILABLE_CMD}; \ ppid=`${PS} -p $$$$ -o ppid | ${AWK} 'NR == 2 { print $$1 }'`; \ - if ${TEST} -z "$$ppid"; then \ + if [ -z "$$ppid" ]; then \ ${ERROR_MSG} "No parent process ID found."; \ exit 1; \ fi; \ - while ${TRUE}; do \ - if ${TEST} -f /var/run/dmesg.boot -a -f "$$lockfile"; then \ + while :; do \ + if [ -f /var/run/dmesg.boot -a -f "$$lockfile" ]; then \ rebooted=`${FIND} /var/run/dmesg.boot -newer "$$lockfile" -print`; \ - if ${TEST} -n "$$rebooted"; then \ + if [ "$$rebooted" ]; then \ ${STEP_MSG} "Removing stale $$lockfile"; \ ${RM} -f "$$lockfile"; \ fi; \ @@ -77,10 +99,8 @@ _ACQUIRE_LOCK_CMD= \ break; \ fi; \ lockpid=`${CAT} "$$lockfile"`; \ - case ${PKGSRC_LOCKTYPE:Q}"" in \ - once) ${ERROR_MSG} "Lock ${.TARGET} is held by pid $$lockpid"; \ - exit 1; \ - ;; \ + case "$$locktype" in \ + once) ${FAIL_MSG} "Lock ${.TARGET} is held by pid $$lockpid" ;; \ sleep) ${STEP_MSG} "Lock ${.TARGET} is held by pid $$lockpid"; \ ${SLEEP} ${PKGSRC_SLEEPSECS}; \ ;; \ @@ -108,27 +128,37 @@ _RELEASE_LOCK_CMD+= \ .PHONY: acquire-lock release-lock .PHONY: acquire-localbase-lock release-localbase-lock -.if ${PKGSRC_LOCKTYPE} == "none" -acquire-lock release-lock acquire-localbase-lock release-localbase-lock: .USE +.if ${LOCALBASE_LOCKTYPE} == "none" +acquire-localbase-lock release-localbase-lock: .USE + @${DO_NADA} +.else +acquire-localbase-lock: .USE + ${RUN} \ + lockfile=${_LOCALBASE_LOCKFILE}; \ + locktype=${LOCALBASE_LOCKTYPE}; \ + ${_ACQUIRE_LOCK_CMD} + +release-localbase-lock: .USE + ${RUN} \ + lockfile=${_LOCALBASE_LOCKFILE}; \ + locktype=${LOCALBASE_LOCKTYPE}; \ + ${_RELEASE_LOCK_CMD} +.endif + +.if ${WRKDIR_LOCKTYPE} == "none" +acquire-lock release-lock: .USE @${DO_NADA} .else acquire-lock: .USE - ${_PKG_SILENT}${_PKG_DEBUG} set -e; \ + ${RUN} \ lockfile=${_WRKDIR_LOCKFILE}; \ + locktype=${WRKDIR_LOCKTYPE}; \ ${_ACQUIRE_LOCK_CMD} release-lock: .USE - ${_PKG_SILENT}${_PKG_DEBUG} set -e; \ + ${RUN} \ lockfile=${_WRKDIR_LOCKFILE}; \ + locktype=${WRKDIR_LOCKTYPE}; \ ${_RELEASE_LOCK_CMD} -acquire-localbase-lock: .USE - ${_PKG_SILENT}${_PKG_DEBUG} set -e; \ - lockfile=${_LOCALBASE_LOCKFILE}; \ - ${_ACQUIRE_LOCK_CMD} - -release-localbase-lock: .USE - ${_PKG_SILENT}${_PKG_DEBUG} set -e; \ - lockfile=${_LOCALBASE_LOCKFILE}; \ - ${_RELEASE_LOCK_CMD} .endif |