pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/mk Moved the locking code from bsd.pkg.mk into its own...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/322cb9b7b788
branches:  trunk
changeset: 517090:322cb9b7b788
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Fri Aug 04 05:55:18 2006 +0000

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

 mk/bsd.pkg.mk          |  75 +--------------------------------------------
 mk/internal/locking.mk |  82 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 73 deletions(-)

diffs (175 lines):

diff -r 9b3918582aaf -r 322cb9b7b788 mk/bsd.pkg.mk
--- a/mk/bsd.pkg.mk     Fri Aug 04 01:10:42 2006 +0000
+++ b/mk/bsd.pkg.mk     Fri Aug 04 05:55:18 2006 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: bsd.pkg.mk,v 1.1880 2006/08/03 19:12:42 rillig Exp $
+#      $NetBSD: bsd.pkg.mk,v 1.1881 2006/08/04 05:55:18 rillig Exp $
 #
 # This file is in the public domain.
 #
@@ -605,78 +605,7 @@
 # adding pre-* or post-* targets/scripts, override these.
 ################################################################
 
-# acquire-lock, release-lock are .USE macro targets for acquiring and
-# release coarse-grained locks.
-#
-_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
+.include "${PKGSRCDIR}/mk/internal/locking.mk"
 
 .PHONY: makedirs
 makedirs: ${WRKDIR}
diff -r 9b3918582aaf -r 322cb9b7b788 mk/internal/locking.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/mk/internal/locking.mk    Fri Aug 04 05:55:18 2006 +0000
@@ -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



Home | Main Index | Thread Index | Old Index