Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 May 2012 22:33:24 +0000
From:      scher@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r236691 - in soc2012/scher/par_ports/head: Mk lock
Message-ID:  <20120529223324.E31DC106566C@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: scher
Date: Tue May 29 22:33:24 2012
New Revision: 236691
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=236691

Log:
  [fixed] bsd.parallel.mk - new locking behaviour
  	bsd.port.mk - few changes just to match new locking behaviour
  [new_feature] bsd.port.mk - create ${LOCK_DIR} if it is missed
  	bsd.parallel.mk - check-lock target
  
  All ports lock files are moved to seperate directory.
  bsd.parallel.mk:
  ${PORTSDIR}/lock - is used to keep ports lock files
  ${_parv_LOCK_DIR_LOCK_FILE} - port's lock file name - is set to ${PKGNAME}
  Reason: Former changes make possible to implement sufficient
  conflicts checking redisign. It was impossible to find port's dir in pots tree
  using package name RE in ${CONFLICTS} variable. Now it is possible just to explore
  ${LOCK_DIR}.
  
  Submitted by: Alexander Pronin

Added:
  soc2012/scher/par_ports/head/lock/
Modified:
  soc2012/scher/par_ports/head/Mk/bsd.parallel.mk
  soc2012/scher/par_ports/head/Mk/bsd.port.mk

Modified: soc2012/scher/par_ports/head/Mk/bsd.parallel.mk
==============================================================================
--- soc2012/scher/par_ports/head/Mk/bsd.parallel.mk	Tue May 29 21:59:09 2012	(r236690)
+++ soc2012/scher/par_ports/head/Mk/bsd.parallel.mk	Tue May 29 22:33:24 2012	(r236691)
@@ -65,7 +65,9 @@
 #####################################################
 # Locking variables and tools
 #PKG_DBDIR?=		/var/db/pkg
-_parv_LOCK_FILE= .lock
+LOCK_DIR= ${PORTSDIR}/lock
+_parv_PKG_DBDIR_LOCK_FILE= .lock
+_parv_LOCK_DIR_LOCK_FILE= ${PKGNAME}
 
 _parv_WAIT_FOR_LOCK_TIME= 5
 _parv_WAIT_FOR_UNLOCK_TIME= 15
@@ -88,13 +90,15 @@
 #
 # If the directory is locked this script returns ${_parv_ON_LOCK_EXIT_STATUS}.
 #
-# ${${_lock_dir}} == ${PKG_DBDIR} OR ${.CURDIR}
+# ${${_lock_dir}} == ${PKG_DBDIR} OR ${LOCK_DIR}
 #
-.for _lock_dir in PKG_DBDIR .CURDIR
+.for _lock_dir in PKG_DBDIR LOCK_DIR
 # _parv_PKG_DBDIR_LOCK_SEQ
-# _parv_.CURDIR_LOCK_SEQ
+# _parv_LOCK_DIR_LOCK_SEQ
 #
-_parv_${_lock_dir}_LOCK_SEQ= \
+_parv_LOCK_FILE:= ${_parv_${_lock_dir}_LOCK_FILE}
+
+_parv_${_lock_dir}_LOCK_SEQ:= \
 	${CHMOD} 777 ${${_lock_dir}}/${_parv_LOCK_FILE}; \
 	pid=$$(${CAT} ${${_lock_dir}}/${_parv_LOCK_FILE}); \
 	if [ $${pid} ]; then \
@@ -105,13 +109,13 @@
 			${_dparv_START_OUTPUT}; \
 			${ECHO_CMD} "Dir: ${${_lock_dir}}   Stalled lock Detected!"; \
 			${ECHO_CMD} "Deleting stalled lock. PID=$${pid}"; \
-			${ECHO_CMD} "Locking: ${${_lock_dir}}"; \
+			${ECHO_CMD} "Locking: ${${_lock_dir}}/${_parv_LOCK_FILE}"; \
 			${_dparv_END_OUTPUT}; \
 			${ECHO_CMD} ${.MAKE.PID} >  ${${_lock_dir}}/${_parv_LOCK_FILE}; \
 		fi; \
 	else \
 		${_dparv_START_OUTPUT}; \
-		${ECHO_CMD} "Locking: ${${_lock_dir}}"; \
+		${ECHO_CMD} "Locking: ${${_lock_dir}}/${_parv_LOCK_FILE}"; \
 		${_dparv_END_OUTPUT}; \
 		${ECHO_CMD} ${.MAKE.PID} > ${${_lock_dir}}/${_parv_LOCK_FILE}; \
 	fi
@@ -119,11 +123,11 @@
 #####################################################
 
 # _parv_PKG_DBDIR_DO_LOCK
-# _parv_.CURDIR_DO_LOCK
+# _parv_LOCK_DIR_DO_LOCK
 # This scripts handles exit status of lockf(1) call.
 # It substitutes exit status 75 of lockf(1) for ${_parv_ON_LOCK_EXIT_STATUS} and pushes it.
 #
-_parv_${_lock_dir}_DO_LOCK= \
+_parv_${_lock_dir}_DO_LOCK:= \
 	lockf -k -t ${_parv_WAIT_FOR_LOCK_TIME} ${${_lock_dir}}/${_parv_LOCK_FILE} ${SH} -c '${_parv_${_lock_dir}_LOCK_SEQ}' || { \
 		status=$$?; \
 			if [ $${status} -eq ${_parv_LOCKF_EX_TEMPFAIL} ] || \
@@ -141,11 +145,11 @@
 
 # Loops to lock directory
 # _parv_PKG_DBDIR_LOCK_LOOP
-# _parv_.CURDIR_LOCK_LOOP
+# _parv_LOCK_DIR_LOCK_LOOP
 # $${attempts} - Number of attempts to lock a directory. Exetranl variable.
 # 				 Default value = 1, if this var is not set.
 #				 Set this variable to -1 for infinity loop.
-# e.g. ( attempts=10; ${_parv_.CURDIR_LOCK_LOOP} ) && ..... || ....
+# e.g. ( attempts=10; ${_parv_LOCK_DIR_LOCK_LOOP} ) && ..... || ....
 #
 _parv_${_lock_dir}_LOCK_LOOP= \
 	enable_feedback=${_parv_ON_LOCK_FEEDBACK_TIMEOUT}; \
@@ -158,7 +162,7 @@
 			elif [ $${status} -eq ${_parv_ON_LOCK_EXIT_STATUS} ]; then \
 				if [ $$(( $${enable_feedback} % ${_parv_ON_LOCK_FEEDBACK_TIMEOUT} )) -eq 0 ]; then \
 					${_dparv_START_OUTPUT}; \
-					${ECHO_CMD} "Unable to lock ${${_lock_dir}}"; \
+					${ECHO_CMD} "Unable to lock ${${_lock_dir}}/${_parv_LOCK_FILE}"; \
 					${ECHO_CMD} "Dir: ${${_lock_dir}}   is already locked by another working process ..."; \
 					${ECHO_CMD} "Waiting for unlock  ........................................................."; \
 					${_dparv_END_OUTPUT}; \
@@ -176,13 +180,13 @@
 #####################################################
 
 # _parv_PKG_DBDIR_DO_UNLOCK
-# _parv_.CURDIR_DO_UNLOCK
+# _parv_LOCK_DIR_DO_UNLOCK
 #
-_parv_${_lock_dir}_DO_UNLOCK= \
+_parv_${_lock_dir}_DO_UNLOCK:= \
 	lockf -k -t ${_parv_WAIT_FOR_UNLOCK_TIME} ${${_lock_dir}}/${_parv_LOCK_FILE} \
 		${RM} ${${_lock_dir}}/${_parv_LOCK_FILE} && { \
 			${_dparv_START_OUTPUT}; \
-			${ECHO_CMD} "Dir: ${${_lock_dir}}   is unlocked"; \
+			${ECHO_CMD} "Dir: ${${_lock_dir}}/${_parv_LOCK_FILE}   is unlocked"; \
 			${_dparv_END_OUTPUT}; \
 		} || { \
 			${_dparv_START_OUTPUT}; \
@@ -193,38 +197,38 @@
 		
 
 .endfor # _lock_dir in PKG_DBDIR .CURDIR
-
+.undef _parv_LOCK_FILE
 #####################################################
 
 # _parv_CHECK_SEQ
 # _parv_CHECK_LOCK
 # The former variables Implement check for lock utility
-# $${dir} - dir to check. External variable for script. Assign this variable
-# appropriate value before executing this script e.g. ( dir=/some/dir/to/check; ${_parv_CHECK_LOCK} ) || ...
-# Script exits with status ${_parv_ON_LOCK_EXIT_STATUS} if $${dir} is locked
-#
+# $${pkg_name} - port to check. External variable for script. Supports shell RE. Assign this variable
+# appropriate value before executing this script e.g. ( pkg_name=apache-[1234]; ${_parv_CHECK_LOCK} ) || ...
+# Script exits with status ${_parv_ON_LOCK_EXIT_STATUS} if $${pkg_name} is locked
+# 
 _parv_CHECK_SEQ= \
-	${CHMOD} 777 $${dir}/${_parv_LOCK_FILE}; \
-	pid=\$$(${CAT} $${dir}/${_parv_LOCK_FILE}); \
+	${CHMOD} 777 ${LOCK_DIR}/$${pkg_name}; \
+	pid=\$$(${CAT} ${LOCK_DIR}/$${pkg_name}); \
 	if [ \$${pid} ]; then \
 		ps -p \$${pid} > /dev/null && status=\$$? || status=\$$?; \
 		if [ \$${status} -eq 0 ]; then \
 			${_dparv_START_OUTPUT}; \
-			${ECHO_CMD} Unable to lock $${dir}; \
-			${ECHO_CMD} Dir: $${dir}   is already locked by another working process ...; \
+			${ECHO_CMD} Unable to lock ${LOCK_DIR}/$${pkg_name}; \
+			${ECHO_CMD} Dir: ${LOCK_DIR}   is already locked by another working process ...; \
 			${_dparv_START_OUTPUT}; \
 			exit ${_parv_ON_LOCK_EXIT_STATUS}; \
 		else \
 			${_dparv_START_OUTPUT}; \
-			${ECHO_CMD} Dir: $${dir}   Stalled lock Detected!; \
+			${ECHO_CMD} Dir: ${LOCK_DIR}/$${pkg_name}   Stalled lock Detected!; \
 			${ECHO_CMD} Deleting stalled lock. PID=\$${pid}; \
 			${_dparv_END_OUTPUT}; \
 		fi; \
 	fi; \
-	${RM} -rf $${dir}/${_parv_LOCK_FILE}
+	${RM} -rf ${LOCK_DIR}/$${pkg_name}
 
 _parv_CHECK_LOCK= \
-	lockf -k -t ${_parv_WAIT_FOR_LOCK_TIME} $${dir}/${_parv_LOCK_FILE} ${SH} -c "${_parv_CHECK_SEQ}" || { \
+	lockf -k -t ${_parv_WAIT_FOR_LOCK_TIME} ${LOCK_DIR}/$${pkg_name} ${SH} -c "${_parv_CHECK_SEQ}" || { \
 		status=$$?; \
 			if [ $${status} -eq ${_parv_LOCKF_EX_TEMPFAIL} ] || \
 					[ $${status} -eq ${_parv_ON_LOCK_EXIT_STATUS} ]; then \
@@ -237,9 +241,21 @@
 			fi; \
 	}
 
+_parv_ON_LOCK_EXIT_SEQ= \
+	status=$$?; \
+	if [ $${status} -eq  ${_parv_ON_LOCK_EXIT_STATUS} ]; then \
+		${_parv_KILL} -${_parv_KILL_SIGNAL} ${.MAKE.PID} && \
+		${_parv_PKILL} ${_parv_PKILL_FLAGS} $$$$; \
+	else \
+		exit $${status}; \
+	fi
+
 # End of Locking variables and tools section
 #####################################################
 
+check-lock:
+	@( pkg_name=${PKGNAME}; ${_parv_CHECK_LOCK} ) || { ${_parv_ON_LOCK_EXIT_SEQ}; }
+	
 do-lock:
 	@${DO_NADA}
 

Modified: soc2012/scher/par_ports/head/Mk/bsd.port.mk
==============================================================================
--- soc2012/scher/par_ports/head/Mk/bsd.port.mk	Tue May 29 21:59:09 2012	(r236690)
+++ soc2012/scher/par_ports/head/Mk/bsd.port.mk	Tue May 29 22:33:24 2012	(r236691)
@@ -1530,19 +1530,17 @@
 .if defined(_parv_WANT_PARALLEL_BUILD) || !defined(IGNORE_PATH_CHECKS)
 .BEGIN:
 .	if defined(_parv_WANT_PARALLEL_BUILD)
+	@if [ ! -d ${LOCK_DIR} ]; then \
+		${_dparv_START_OUTPUT}; \
+		${ECHO_CMD} "Creating lock dir"; \
+		${_dparv_END_OUTPUT}; \
+		${MKDIR} ${LOCK_DIR}; \
+	fi
 .		if ${_parv_IS_DEFAULT_TARGET}
 .			if defined(INSTALLS_DEPENDS)
-	@( ${_parv_.CURDIR_LOCK_LOOP} ) || { \
-		status=$$?; \
-		if [ $${status} -eq  ${_parv_ON_LOCK_EXIT_STATUS} ]; then \
-			${_parv_KILL} -${_parv_KILL_SIGNAL} ${.MAKE.PID} && \
-			${_parv_PKILL} ${_parv_PKILL_FLAGS} $$$$; \
-		else \
-			exit $${status}; \
-		fi; \
-	}
+	@( ${_parv_LOCK_DIR_LOCK_LOOP} ) || { ${_parv_ON_LOCK_EXIT_SEQ}; }
 .			else
-	@attempts=-1; ${_parv_.CURDIR_LOCK_LOOP}
+	@attempts=-1; ${_parv_LOCK_DIR_LOCK_LOOP}
 .			endif
 .		endif
 .	endif
@@ -1559,7 +1557,7 @@
 .if defined(_parv_WANT_PARALLEL_BUILD)
 .END:
 .	if ${_parv_IS_DEFAULT_TARGET}
-	@${_parv_.CURDIR_DO_UNLOCK}
+	@${_parv_LOCK_DIR_DO_UNLOCK}
 .	endif
 .endif
 ############### END OF PAR_PORTS SPECIFIC COMMENT LINE  ###############
@@ -5167,9 +5165,9 @@
 			fi; \
 		fi; \
 		if [ ${_parv_WANT_PARALLEL_BUILD} ] && [ $${notfound} -eq 1 ]; then \
-			( ${_parv_CHECK_LOCK} ) || { \
+			( cd $${dir}; ${MAKE} check-lock ) || { \
 			status=$$?; \
-			if [ $${status} -eq ${_parv_ON_LOCK_EXIT_STATUS} ]; then \
+			if [ $${status} -eq ${_parv_MAKE_LOCK_EXIT_STATUS} ]; then \
 				( ${_parv_PKG_DBDIR_DO_UNLOCK} ); \
 				${ECHO_CMD} $${prog} may be installing now.; \
 				sleep 2; \
@@ -5232,9 +5230,9 @@
 			notfound=1; \
 		fi; \
 		if [ ${_parv_WANT_PARALLEL_BUILD} ] && [ $${notfound} -eq 1 ]; then \
-			( ${_parv_CHECK_LOCK} ) || { \
+			( cd $${dir}; ${MAKE} check-lock ) || { \
 			status=$$?; \
-			if [ $${status} -eq ${_parv_ON_LOCK_EXIT_STATUS} ]; then \
+			if [ $${status} -eq ${_parv_MAKE_LOCK_EXIT_STATUS} ]; then \
 				( ${_parv_PKG_DBDIR_DO_UNLOCK} ); \
 				${ECHO_CMD} $${prog} may be installing now.; \
 				sleep 2; \



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120529223324.E31DC106566C>