diff options
author | rillig <rillig@pkgsrc.org> | 2006-08-04 05:55:18 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2006-08-04 05:55:18 +0000 |
commit | 6e662c83f1435f4ec4c96de6d5f2500798862732 (patch) | |
tree | cabbecd04591ca5f39f3d4224e0cce4709c3faf9 /mk/internal | |
parent | 185cab7e76a4908508f446fd22553e070b8dccc7 (diff) | |
download | pkgsrc-6e662c83f1435f4ec4c96de6d5f2500798862732.tar.gz |
Moved the locking code from bsd.pkg.mk into its own file. Where here,
added a more detailed header comment and fixed a bug concerning lockdir.
Diffstat (limited to 'mk/internal')
-rw-r--r-- | mk/internal/locking.mk | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/mk/internal/locking.mk b/mk/internal/locking.mk new file mode 100644 index 00000000000..7a0bed0c484 --- /dev/null +++ b/mk/internal/locking.mk @@ -0,0 +1,82 @@ +# $NetBSD: locking.mk,v 1.1 2006/08/04 05:55:18 rillig Exp $ +# + +# acquire-lock and release-lock are two .USE macro targets that aquire +# and release coarse-grained locks. There are two areas of pkgsrc that +# can be locked: The WRKDIR of a specific package or the LOCALBASE. +# Which of those is locked depends on the name of the target where the +# {acquire,release}-lock macro is used. If it contains -install-, as for +# example acquire-install-lock, LOCALBASE is locked. Otherwise, WRKDIR +# is locked. +# +# + +_WRKDIR_LOCKFILE= ${WRKDIR}/.lockfile +_PREFIX_LOCKFILE= ${PKG_DBDIR}/.lockfile +_GET_LOCKFILE_CMD= \ + case ${.TARGET} in \ + *-install-*) lockfile=${_PREFIX_LOCKFILE};; \ + *) lockfile=${_WRKDIR_LOCKFILE};; \ + esac + +acquire-lock: .USE +.if ${PKGSRC_LOCKTYPE} == "none" + @${DO_NADA} +.else + @if ${TEST} ! -x ${SHLOCK:Q}""; then \ + ${ERROR_MSG} "The ${SHLOCK:Q} utility does not exist, and is necessary for locking."; \ + ${ERROR_MSG} "Please \""${MAKE:Q}" install\" in ../../pkgtools/shlock."; \ + exit 1; \ + fi +. if !defined(OBJHOSTNAME) + @${ERROR_MSG} "PKGSRC_LOCKTYPE needs OBJHOSTNAME defined."; \ + exit 1 +. endif + ${_PKG_SILENT}${_PKG_DEBUG}set -e; \ + ${_GET_LOCKFILE_CMD}; \ + ppid=`${PS} -p $$$$ -o ppid | ${AWK} 'NR == 2 { print $$1 }'`; \ + if ${TEST} -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 \ + rebooted=`${FIND} /var/run/dmesg.boot -newer "$$lockfile" -print`; \ + if ${TEST} -n "$$rebooted"; then \ + ${STEP_MSG} "Removing stale $$lockfile"; \ + ${RM} -f "$$lockfile"; \ + fi; \ + fi; \ + lockdir=`echo "$$lockfile" | sed "s,/[^/]*\$$,,"`; \ + ${MKDIR} "$$lockdir"; \ + if ${SHLOCK} -f "$$lockfile" -p $$ppid; then \ + break; \ + fi; \ + lockpid=`${CAT} "$$lockfile"`; \ + case ${PKGSRC_LOCKTYPE:Q}"" in \ + once) ${ERROR_MSG} "Lock is held by pid $$lockpid"; \ + exit 1; \ + ;; \ + sleep) ${STEP_MSG} "Lock is held by pid $$lockpid"; \ + ${SLEEP} ${PKGSRC_SLEEPSECS}; \ + ;; \ + esac; \ + done; \ + if ${PKG_VERBOSE:D${TRUE}:U${FALSE}}; then \ + lockpid=`${CAT} "$$lockfile"`; \ + ${STEP_MSG} "Lock acquired for \`\`${.TARGET:S/^acquire-//:S/-lock$//}'' on behalf of process $$lockpid"; \ + fi +.endif + +release-lock: .USE +.if ${PKGSRC_LOCKTYPE} == "none" + @${DO_NADA} +.else + ${_PKG_SILENT}${_PKG_DEBUG} set -e; \ + ${_GET_LOCKFILE_CMD}; \ + if ${PKG_VERBOSE:D${TRUE}:U${FALSE}}; then \ + lockpid=`${CAT} "$$lockfile"`; \ + ${STEP_MSG} "Lock released for \`\`${.TARGET:S/^release-//:S/-lock$//}'' on behalf of process $$lockpid"; \ + fi; \ + ${RM} -f "$$lockfile" +.endif |