summaryrefslogtreecommitdiff
path: root/mk
diff options
context:
space:
mode:
authorrillig <rillig>2006-08-04 20:52:27 +0000
committerrillig <rillig>2006-08-04 20:52:27 +0000
commite137a2b3fcdb863c1612110706e2ef09b46feb25 (patch)
treec6403946f8ea93813813b4b26d0a6531fa3c42b7 /mk
parent9d8ae8279a4e165ea7b3395cc36f5aed7025ae75 (diff)
downloadpkgsrc-e137a2b3fcdb863c1612110706e2ef09b46feb25.tar.gz
Fixed the locking, as suggested by Johnny on the tech-pkg mailing list.
Added two targets acquire-localbase-lock and release-localbase-lock, which mark the complete LOCALBASE directory as locked, so that multiple packages cannot run the install, deinstall or bin-install targets at the same time. The install target aquires locks in both WRKSRC and LOCALBASE, the other two targets only need the LOCALBASE lock, since they may be run without WRKSRC being present on the system. locking.mk must be included before tools.mk and the PKG_FAIL_REASON check.
Diffstat (limited to 'mk')
-rw-r--r--mk/bsd.pkg.mk12
-rw-r--r--mk/install/bin-install.mk6
-rw-r--r--mk/install/deinstall.mk13
-rw-r--r--mk/install/install.mk6
-rw-r--r--mk/internal/locking.mk131
5 files changed, 111 insertions, 57 deletions
diff --git a/mk/bsd.pkg.mk b/mk/bsd.pkg.mk
index a9d9254f81d..897c7822036 100644
--- a/mk/bsd.pkg.mk
+++ b/mk/bsd.pkg.mk
@@ -1,4 +1,4 @@
-# $NetBSD: bsd.pkg.mk,v 1.1883 2006/08/04 07:04:38 rillig Exp $
+# $NetBSD: bsd.pkg.mk,v 1.1884 2006/08/04 20:52:27 rillig Exp $
#
# This file is in the public domain.
#
@@ -410,12 +410,8 @@ USE_TOOLS+= expr
USE_TOOLS+= tee tsort
.endif
-# We need shlock and sleep if we're using locking to synchronize multiple
-# builds over the same pkgsrc tree.
-#
-.if ${PKGSRC_LOCKTYPE} != "none"
-USE_TOOLS+= shlock sleep
-.endif
+# Locking
+.include "${PKGSRCDIR}/mk/internal/locking.mk"
# Tools
.include "../../mk/tools/bsd.tools.mk"
@@ -605,8 +601,6 @@ all: ${_PKGSRC_BUILD_TARGETS}
# adding pre-* or post-* targets/scripts, override these.
################################################################
-.include "${PKGSRCDIR}/mk/internal/locking.mk"
-
.PHONY: makedirs
makedirs: ${WRKDIR}
diff --git a/mk/install/bin-install.mk b/mk/install/bin-install.mk
index 8ef5fabd848..0fb73ed3d2b 100644
--- a/mk/install/bin-install.mk
+++ b/mk/install/bin-install.mk
@@ -1,4 +1,4 @@
-# $NetBSD: bin-install.mk,v 1.2 2006/08/04 07:17:58 rillig Exp $
+# $NetBSD: bin-install.mk,v 1.3 2006/08/04 20:52:27 rillig Exp $
#
# This file provides the following targets:
@@ -28,8 +28,8 @@ _SU_BIN_INSTALL_TARGETS+= locked-su-bin-install
_SU_BIN_INSTALL_TARGETS+= release-bin-install-lock
.PHONY: acquire-bin-install-lock release-bin-install-lock
-acquire-bin-install-lock: acquire-lock
-release-bin-install-lock: release-lock
+acquire-bin-install-lock: acquire-localbase-lock
+release-bin-install-lock: release-localbase-lock
# Install binary pkg, without strict uptodate-check first
.PHONY: su-bin-install
diff --git a/mk/install/deinstall.mk b/mk/install/deinstall.mk
index 0f5423b6fe7..9ae3e50edde 100644
--- a/mk/install/deinstall.mk
+++ b/mk/install/deinstall.mk
@@ -1,4 +1,4 @@
-# $NetBSD: deinstall.mk,v 1.4 2006/08/03 19:12:43 rillig Exp $
+# $NetBSD: deinstall.mk,v 1.5 2006/08/04 20:52:27 rillig Exp $
# DEINSTALLDEPENDS controls whether dependencies and dependents are also
# removed when a package is de-installed. The valid values are:
@@ -21,7 +21,16 @@ deinstall: su-target
@${PHASE_MSG} "Deinstalling for ${PKGNAME}"
.endif
-su-deinstall: acquire-install-lock deinstall-pkg release-install-lock install-clean
+_SU_DEINSTALL_TARGETS= acquire-deinstall-lock
+_SU_DEINSTALL_TARGETS+= deinstall-pkg
+_SU_DEINSTALL_TARGETS+= release-deinstall-lock
+_SU_DEINSTALL_TARGETS+= install-clean
+su-deinstall: ${_SU_DEINSTALL_TARGETS}
+.ORDER: ${_SU_DEINSTALL_TARGETS}
+
+.PHONY: acquire-deinstall-lock release-deinstall-lock
+acquire-deinstall-lock: acquire-localbase-lock
+release-deinstall-lock: release-localbase-lock
MAKEFLAGS.su-deinstall= DEINSTALLDEPENDS=${DEINSTALLDEPENDS}
diff --git a/mk/install/install.mk b/mk/install/install.mk
index bac0c4db5fb..3f4c7368b7e 100644
--- a/mk/install/install.mk
+++ b/mk/install/install.mk
@@ -1,4 +1,4 @@
-# $NetBSD: install.mk,v 1.15 2006/07/27 21:46:46 jlam Exp $
+# $NetBSD: install.mk,v 1.16 2006/08/04 20:52:27 rillig Exp $
######################################################################
### install (PUBLIC)
@@ -25,8 +25,8 @@ install: barrier
.endif
.PHONY: acquire-install-lock release-install-lock
-acquire-install-lock: acquire-lock
-release-install-lock: release-lock
+acquire-install-lock: acquire-lock acquire-localbase-lock
+release-install-lock: release-lock release-localbase-lock
.if exists(${_COOKIE.install})
${_COOKIE.install}:
diff --git a/mk/internal/locking.mk b/mk/internal/locking.mk
index 7a0bed0c484..4943835212e 100644
--- a/mk/internal/locking.mk
+++ b/mk/internal/locking.mk
@@ -1,39 +1,62 @@
-# $NetBSD: locking.mk,v 1.1 2006/08/04 05:55:18 rillig Exp $
+# $NetBSD: locking.mk,v 1.2 2006/08/04 20:52:27 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.
+# This file provides the following .USE targets:
+#
+# acquire-lock
+# Acquires a coarse-grained lock in WRKDIR.
+#
+# release-lock
+# Releases the lock in WRKDIR.
+#
+# acquire-localbase-lock
+# Acquires a coarse-grained lock in LOCALBASE.
+#
+# release-localbase-lock
+# Releases the lock in LOCALBASE.
#
-#
_WRKDIR_LOCKFILE= ${WRKDIR}/.lockfile
-_PREFIX_LOCKFILE= ${PKG_DBDIR}/.lockfile
-_GET_LOCKFILE_CMD= \
- case ${.TARGET} in \
- *-install-*) lockfile=${_PREFIX_LOCKFILE};; \
- *) lockfile=${_WRKDIR_LOCKFILE};; \
- esac
+_LOCALBASE_LOCKFILE= ${LOCALBASE}/.lockfile
+
+#
+# Sanity checks.
+#
-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
+# No further checks.
+.elif ${PKGSRC_LOCKTYPE} == "once" || ${PKGSRC_LOCKTYPE} == "sleep"
. if !defined(OBJHOSTNAME)
- @${ERROR_MSG} "PKGSRC_LOCKTYPE needs OBJHOSTNAME defined."; \
- exit 1
+PKG_FAIL_REASON+= "[locking.mk] PKGSRC_LOCKTYPE needs OBJHOSTNAME defined."
. endif
- ${_PKG_SILENT}${_PKG_DEBUG}set -e; \
- ${_GET_LOCKFILE_CMD}; \
+.else
+PKG_FAIL_REASON+= "[locking.mk] PKGSRC_LOCKTYPE must be one of {none,once,sleep}, not ${PKGSRC_LOCKTYPE}."
+.endif
+
+#
+# Needed tools.
+#
+
+.if ${PKGSRC_LOCKTYPE} != "none"
+USE_TOOLS+= shlock
+.endif
+.if ${PKGSRC_LOCKTYPE} == "sleep"
+USE_TOOLS+= sleep
+.endif
+
+#
+# The commands.
+#
+
+_CHECK_IF_SHLOCK_IS_AVAILABLE_CMD= \
+ ${TEST} -x ${SHLOCK:Q}"" || { \
+ ${ERROR_MSG} "[locking.mk] shlock is not installed."; \
+ ${ERROR_MSG} "[locking.mk] Please \"cd ../../pkgtools/shlock && ${MAKE} install\"."; \
+ exit 1; \
+ }
+
+_ACQUIRE_LOCK_CMD= \
+ ${_CHECK_IF_SHLOCK_IS_AVAILABLE_CMD}; \
ppid=`${PS} -p $$$$ -o ppid | ${AWK} 'NR == 2 { print $$1 }'`; \
if ${TEST} -z "$$ppid"; then \
${ERROR_MSG} "No parent process ID found."; \
@@ -49,7 +72,7 @@ acquire-lock: .USE
fi; \
lockdir=`echo "$$lockfile" | sed "s,/[^/]*\$$,,"`; \
${MKDIR} "$$lockdir"; \
- if ${SHLOCK} -f "$$lockfile" -p $$ppid; then \
+ if ${SHLOCK} -f "$$lockfile" -p "$$ppid"; then \
break; \
fi; \
lockpid=`${CAT} "$$lockfile"`; \
@@ -61,22 +84,50 @@ acquire-lock: .USE
${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
+ done;
+.if defined(PKG_VERBOSE)
+_ACQUIRE_LOCK_CMD+= \
+ lockpid=`${CAT} "$$lockfile"`; \
+ ${STEP_MSG} "Lock $$lockfile acquired for \`\`${.TARGET:S/^acquire-//:S/-lock$//}'' on behalf of process $$lockpid";
.endif
-release-lock: .USE
+_RELEASE_LOCK_CMD= # nothing
+.if defined(PKG_VERBOSE)
+_RELEASE_LOCK_CMD+= \
+ lockpid=`${CAT} "$$lockfile"`; \
+ ${STEP_MSG} "Lock $$lockfile released for \`\`${.TARGET:S/^release-//:S/-lock$//}'' on behalf of process $$lockpid";
+.endif
+_RELEASE_LOCK_CMD+= \
+ ${RM} -f "$$lockfile"
+
+#
+# The targets.
+#
+
+.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
@${DO_NADA}
.else
+acquire-lock: .USE
${_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"
+ lockfile=${_WRKDIR_LOCKFILE}; \
+ ${_ACQUIRE_LOCK_CMD}
+
+release-lock: .USE
+ ${_PKG_SILENT}${_PKG_DEBUG} set -e; \
+ lockfile=${_WRKDIR_LOCKFILE}; \
+ ${_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