pkgsrc-Changes archive

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

CVS commit: pkgsrc/mk



Module Name:    pkgsrc
Committed By:   rillig
Date:           Sun May 10 06:52:50 UTC 2020

Modified Files:
        pkgsrc/mk: bsd.pkg.mk
Added Files:
        pkgsrc/mk/misc: locking.mk
Removed Files:
        pkgsrc/mk/internal: locking.mk

Log Message:
mk: move locking.mk from internal to misc

Locking is not really internal since it has user-settable variables.


To generate a diff of this commit:
cvs rdiff -u -r1.2038 -r1.2039 pkgsrc/mk/bsd.pkg.mk
cvs rdiff -u -r1.10 -r0 pkgsrc/mk/internal/locking.mk
cvs rdiff -u -r0 -r1.1 pkgsrc/mk/misc/locking.mk

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/mk/bsd.pkg.mk
diff -u pkgsrc/mk/bsd.pkg.mk:1.2038 pkgsrc/mk/bsd.pkg.mk:1.2039
--- pkgsrc/mk/bsd.pkg.mk:1.2038 Sun May  3 10:34:00 2020
+++ pkgsrc/mk/bsd.pkg.mk        Sun May 10 06:52:49 2020
@@ -1,4 +1,4 @@
-#      $NetBSD: bsd.pkg.mk,v 1.2038 2020/05/03 10:34:00 rillig Exp $
+#      $NetBSD: bsd.pkg.mk,v 1.2039 2020/05/10 06:52:49 rillig Exp $
 #
 # This file is in the public domain.
 #
@@ -392,7 +392,7 @@ USE_TOOLS+= expr
 .endif
 
 # Locking
-.include "internal/locking.mk"
+.include "misc/locking.mk"
 
 # Tools
 .include "tools/bsd.tools.mk"

Added files:

Index: pkgsrc/mk/misc/locking.mk
diff -u /dev/null pkgsrc/mk/misc/locking.mk:1.1
--- /dev/null   Sun May 10 06:52:50 2020
+++ pkgsrc/mk/misc/locking.mk   Sun May 10 06:52:50 2020
@@ -0,0 +1,168 @@
+# $NetBSD: locking.mk,v 1.1 2020/05/10 06:52:50 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
+#
+# See also: PKGSRC_LOCKTYPE.
+# Keywords: lock locking parallel
+
+# 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_LOCKTYPE?=      ${PKGSRC_LOCKTYPE}
+LOCALBASE_LOCKTYPE?=   ${PKGSRC_LOCKTYPE}
+
+_WRKDIR_LOCKFILE=      ${WRKDIR}/.lockfile
+_LOCALBASE_LOCKFILE=   ${LOCALBASE}/.lockfile
+_LOCKVARS=             WRKDIR_LOCKTYPE LOCALBASE_LOCKTYPE
+
+#
+# Sanity checks.
+#
+
+.for v in ${_LOCKVARS}
+_OK=   no
+.  for t in none once sleep
+.    if ${${v}} == "${t}"
+_OK=   yes
+.    endif
+.  endfor
+.  if ${_OK} != "yes"
+PKG_FAIL_REASON+=      "[locking.mk] ${v} must be one of { none once sleep }, not ${${v}}."
+.  endif
+.endfor
+
+#
+# Needed tools.
+#
+
+.for v in ${_LOCKVARS}
+.  if ${${v}} != "none"
+USE_TOOLS+=            shlock
+.  endif
+.  if ${${v}} == "sleep"
+USE_TOOLS+=            sleep
+.  endif
+.endfor
+
+#
+# The commands.
+#
+
+_CHECK_IF_SHLOCK_IS_AVAILABLE_CMD= \
+       [ "${PKGPATH}" != "pkgtools/shlock" ] || exit 0;                \
+       [ -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 [ -z "$$ppid" ]; then                                        \
+               ${ERROR_MSG} "No parent process ID found.";             \
+               exit 1;                                                 \
+       fi;                                                             \
+       while :; do                                                     \
+               if [ -f /var/run/dmesg.boot -a -f "$$lockfile" ]; then  \
+                       rebooted=`${FIND} /var/run/dmesg.boot -newer "$$lockfile" -print`; \
+                       if [ "$$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 "$$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};                   \
+                       ;;                                              \
+               esac;                                                   \
+       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 ${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
+       ${RUN}                                                          \
+       lockfile=${_WRKDIR_LOCKFILE};                                   \
+       locktype=${WRKDIR_LOCKTYPE};                                    \
+       ${_ACQUIRE_LOCK_CMD}
+
+release-lock: .USE
+       ${RUN}                                                          \
+       lockfile=${_WRKDIR_LOCKFILE};                                   \
+       locktype=${WRKDIR_LOCKTYPE};                                    \
+       ${_RELEASE_LOCK_CMD}
+
+.endif



Home | Main Index | Thread Index | Old Index