pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/mk/internal Made the locking more flexible by letting ...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/cb3126690055
branches:  trunk
changeset: 525665:cb3126690055
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Tue Feb 20 22:11:10 2007 +0000

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

diffstat:

 mk/internal/locking.mk |  102 +++++++++++++++++++++++++++++++-----------------
 1 files changed, 66 insertions(+), 36 deletions(-)

diffs (165 lines):

diff -r 65c3cfdfcf1c -r cb3126690055 mk/internal/locking.mk
--- a/mk/internal/locking.mk    Tue Feb 20 20:47:15 2007 +0000
+++ b/mk/internal/locking.mk    Tue Feb 20 22:11:10 2007 +0000
@@ -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 @@
 _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 @@
                        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 @@
 .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



Home | Main Index | Thread Index | Old Index