pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/mk Fixed the locking, as suggested by Johnny on the te...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/8038e3a5fa95
branches:  trunk
changeset: 517127:8038e3a5fa95
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Fri Aug 04 20:52:27 2006 +0000

description:
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:

 mk/bsd.pkg.mk             |   12 +---
 mk/install/bin-install.mk |    6 +-
 mk/install/deinstall.mk   |   13 +++-
 mk/install/install.mk     |    6 +-
 mk/internal/locking.mk    |  135 +++++++++++++++++++++++++++++++--------------
 5 files changed, 113 insertions(+), 59 deletions(-)

diffs (267 lines):

diff -r 716ee918c127 -r 8038e3a5fa95 mk/bsd.pkg.mk
--- a/mk/bsd.pkg.mk     Fri Aug 04 20:48:25 2006 +0000
+++ b/mk/bsd.pkg.mk     Fri Aug 04 20:52:27 2006 +0000
@@ -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+=    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 @@
 # adding pre-* or post-* targets/scripts, override these.
 ################################################################
 
-.include "${PKGSRCDIR}/mk/internal/locking.mk"
-
 .PHONY: makedirs
 makedirs: ${WRKDIR}
 
diff -r 716ee918c127 -r 8038e3a5fa95 mk/install/bin-install.mk
--- a/mk/install/bin-install.mk Fri Aug 04 20:48:25 2006 +0000
+++ b/mk/install/bin-install.mk Fri Aug 04 20:52:27 2006 +0000
@@ -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+=      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 -r 716ee918c127 -r 8038e3a5fa95 mk/install/deinstall.mk
--- a/mk/install/deinstall.mk   Fri Aug 04 20:48:25 2006 +0000
+++ b/mk/install/deinstall.mk   Fri Aug 04 20:52:27 2006 +0000
@@ -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 @@
        @${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 -r 716ee918c127 -r 8038e3a5fa95 mk/install/install.mk
--- a/mk/install/install.mk     Fri Aug 04 20:48:25 2006 +0000
+++ b/mk/install/install.mk     Fri Aug 04 20:52:27 2006 +0000
@@ -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 @@
 .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 -r 716ee918c127 -r 8038e3a5fa95 mk/internal/locking.mk
--- a/mk/internal/locking.mk    Fri Aug 04 20:48:25 2006 +0000
+++ b/mk/internal/locking.mk    Fri Aug 04 20:52:27 2006 +0000
@@ -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}
+# No further checks.
+.elif ${PKGSRC_LOCKTYPE} == "once" || ${PKGSRC_LOCKTYPE} == "sleep"
+.  if !defined(OBJHOSTNAME)
+PKG_FAIL_REASON+=      "[locking.mk] PKGSRC_LOCKTYPE needs OBJHOSTNAME defined."
+.  endif
 .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."; \
+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;                                                 \
-       fi
-.  if !defined(OBJHOSTNAME)
-       @${ERROR_MSG} "PKGSRC_LOCKTYPE needs OBJHOSTNAME defined.";     \
-       exit 1
-.  endif
-       ${_PKG_SILENT}${_PKG_DEBUG}set -e;                              \
-       ${_GET_LOCKFILE_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                                    \
                ${ERROR_MSG} "No parent process ID found.";             \
@@ -49,7 +72,7 @@
                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 @@
                        ${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_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;                             \
+       lockfile=${_WRKDIR_LOCKFILE};                                   \
+       ${_ACQUIRE_LOCK_CMD}
 
 release-lock: .USE
-.if ${PKGSRC_LOCKTYPE} == "none"
-       @${DO_NADA}
-.else
+       ${_PKG_SILENT}${_PKG_DEBUG} set -e;                             \
+       lockfile=${_WRKDIR_LOCKFILE};                                   \
+       ${_RELEASE_LOCK_CMD}
+
+acquire-localbase-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=${_LOCALBASE_LOCKFILE};                                \
+       ${_ACQUIRE_LOCK_CMD}
+
+release-localbase-lock: .USE
+       ${_PKG_SILENT}${_PKG_DEBUG} set -e;                             \
+       lockfile=${_LOCALBASE_LOCKFILE};                                \
+       ${_RELEASE_LOCK_CMD}
 .endif



Home | Main Index | Thread Index | Old Index