socsvn commit: r236228 - soc2012/scher/par_ports/head/Mk

scher at FreeBSD.org scher at FreeBSD.org
Wed May 23 20:47:09 UTC 2012


Author: scher
Date: Wed May 23 20:47:06 2012
New Revision: 236228
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=236228

Log:
  [new_feature] ${PKG_DBDIR} and ${.CURDIR} specific lock/unlock
  [fixed] do-lock do-unlock targets are depricated
  
  It is possible to lock/unlock ${PKG_DBDIR} and ${.CURDIR}
  For loop generates directory specific variable:
  	_parv_PKG_DBDIR_DO_LOCK - lockf command to lock ${PKG_DBDIR}
  	_parv_.CURDIR_DO_LOCK - lockf command to lock ${.CURDIR}
  	_parv_PKG_DBDIR_LOCK_SEQ, _parv_.CURDIR_LOCK_SEQ - sequences of
  commandes passed to ${SH} lockf command argument.
  e.g. lockf .lock_file ${SH} -c '_parv_PKG_DBDIR_LOCK_SEQ'
  	_parv_PKG_DBDIR_DO_UNLOCK, _parv_.CURDIR_DO_UNLOCK - lockf command
  to unlock directories.
  ---------------------------------
  do-lock, do-unlock targets are depricated.
  Their shell scriptes were delegated to above mentioned XXX_DO_LOCK and
  XXX_DO_UNLOCK variables.
  Reason: It is necessary to provide locking/unlocking from inside other targets.
  Usage of locking/unlocking features as dependency targets is insufficient.
  

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

Modified: soc2012/scher/par_ports/head/Mk/bsd.parallel.mk
==============================================================================
--- soc2012/scher/par_ports/head/Mk/bsd.parallel.mk	Wed May 23 19:25:46 2012	(r236227)
+++ soc2012/scher/par_ports/head/Mk/bsd.parallel.mk	Wed May 23 20:47:06 2012	(r236228)
@@ -10,26 +10,32 @@
 
 _dparv_=
 _parv_=
-#################
+#####################################################
 # Debugging specific tools and variable declarations
 _dparv_START_OUTPUT_MESSAGE= "=================_PAR_PORTS_SPECIFIC_OUTPUT_=============="
 _dparv_END_OUTPUT_MESSAGE= "==============_END_OF_PAR_PORTS_SPECIFIC_OUTPUT_=============="
 
 _dparv_START_OUTPUT= ${ECHO_CMD} ${_dparv_START_OUTPUT_MESSAGE}
 _dparv_END_OUTPUT= ${ECHO_CMD} ${_dparv_END_OUTPUT_MESSAGE}
-#################
+# End of Debugging specific tools and variable declarations section 
+#####################################################
 
 
-#################
+#####################################################
 # Commands
 _parv_KILL= /bin/kill
 _parv_KILL_FLAGS= --
-#################
+
+DO_NADA?=		${TRUE}
+# End of Commands section
+#####################################################
+#####################################################
 # Locking variables and tools
-_parv_DIR_TO_LOCK?=${PORTSDIR}/tmp
-_parv_LOCK_FILE= ${_parv_DIR_TO_LOCK}/.lock
+PKG_DBDIR?=		/var/db/pkg
+_parv_LOCK_FILE= .lock
 
 _parv_WAIT_FOR_LOCK_TIME= 5
+_parv_WAIT_FOR_UNLOCK_TIME= 15
 
 # Senquence of commands to lock a directory using ${_parv_LOCK_FILE}.
 # During evaluation of the following commands lockf(1) is holding lock on ${_parv_LOCK_FILE} file.
@@ -39,45 +45,82 @@
 # Stalled locks cheking enabled.
 #
 # If the directory is locked then make process will be terminated with 143 exit code.
+# If ${_parv_LOCK_FILE} is locked then make process will be terminated with 143 exit code.
+#
+# For loop produces two varuables:
+# _parv_PKG_DBDIR_LOCK_SEQ
+# _parv_.CURDIR_LOCK_SEQ
+# as sequencies of commands to provide locking of ${PKG_DBDIR} and ${.CURDIR} accordingly.
+#
+# ${${_lock_dir}} == ${PKG_DBDIR} OR ${.CURDIR}
+#
+.for _lock_dir in PKG_DBDIR .CURDIR
+# _parv_PKG_DBDIR_LOCK_SEQ
+# _parv_.CURDIR_LOCK_SEQ
 #
-_parv_LOCK_SEQ= \
-	pid=$$(${CAT} ${_parv_LOCK_FILE}); \
+_parv_${_lock_dir}_LOCK_SEQ= \
+	pid=$$(${CAT} ${${_lock_dir}}/${_parv_LOCK_FILE}); \
 	if [ $${pid} ]; then \
 		pgrep -P $${pid} > /dev/null; \
 		status=$$(${ECHO_CMD} $$?); \
 		if [ $${status} -eq 0 ]; then \
 			${_dparv_START_OUTPUT}; \
-			${ECHO_CMD} Unable to lock ${_parv_DIR_TO_LOCK}; \
-			${ECHO_CMD} Dir: ${_parv_DIR_TO_LOCK}   is already locked by another working process ...; \
+			${ECHO_CMD} Unable to lock ${${_lock_dir}}; \
+			${ECHO_CMD} Dir: ${${_lock_dir}}   is already locked by another working process ...; \
 			${_dparv_END_OUTPUT}; \
 			${_parv_KILL} ${_parv_KILL_FLAGS} -${.MAKE.PID}; \
 		else \
 			${_dparv_START_OUTPUT}; \
-			${ECHO_CMD} Dir: ${_parv_DIR_TO_LOCK}   Stalled lock Detected!; \
+			${ECHO_CMD} Dir: ${${_lock_dir}}   Stalled lock Detected!; \
 			${ECHO_CMD} Deleting stalled lock; \
-			${ECHO_CMD} Locking: ${_parv_DIR_TO_LOCK}; \
+			${ECHO_CMD} Locking: ${${_lock_dir}}; \
 			${_dparv_END_OUTPUT}; \
-			${ECHO_CMD} ${.MAKE.PID} > ${_parv_LOCK_FILE}; \
+			${ECHO_CMD} ${.MAKE.PID} >  ${${_lock_dir}}/${_parv_LOCK_FILE}; \
 		fi; \
 	else \
 		${_dparv_START_OUTPUT}; \
-		${ECHO_CMD} Locking: ${_parv_DIR_TO_LOCK}; \
+		${ECHO_CMD} Locking: ${${_lock_dir}}; \
 		${_dparv_END_OUTPUT}; \
-		${ECHO_CMD} ${.MAKE.PID} > ${_parv_LOCK_FILE}; \
-	fi; \
-#################
+		${ECHO_CMD} ${.MAKE.PID} > ${${_lock_dir}}/${_parv_LOCK_FILE}; \
+	fi
 
+# _parv_PKG_DBDIR_DO_LOCK
+# _parv_.CURDIR_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}' || ( \
+		${_dparv_START_OUTPUT}; \
+		${ECHO_CMD} "Unable to lock ${${_lock_dir}}"; \
+		${ECHO_CMD} "Lock file: ${${_lock_dir}}/${_parv_LOCK_FILE} is alredy locked by another working process ..."; \
+		${_dparv_END_OUTPUT}; \
+		${_parv_KILL} ${_parv_KILL_FLAGS} -${.MAKE.PID}; \
+	)
 
-do-lock:
-	@lockf -k -t ${_parv_WAIT_FOR_LOCK_TIME} ${_parv_LOCK_FILE} ${SH} -c '${_parv_LOCK_SEQ}' || ( \
+# _parv_PKG_DBDIR_DO_UNLOCK
+# _parv_.CURDIR_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} "Unable to lock ${_parv_DIR_TO_LOCK}"; \
-		${ECHO_CMD} "Lock file: ${_parv_LOCK_FILE} is alredy locked by another working process ..."; \
+		${ECHO_CMD} Unable to unlock ${${_lock_dir}}; \
 		${_dparv_END_OUTPUT}; \
 		${_parv_KILL} ${_parv_KILL_FLAGS} -${.MAKE.PID}; \
-	); \
+	) \
+) && ( \
+	${_dparv_START_OUTPUT}; \
+	${ECHO_CMD} "Dir: ${${_lock_dir}} is unloked"; \
+	${_dparv_END_OUTPUT}; \
+)
+
+.endfor # _lock_dir in PKG_DBDIR .CURDIR
+
+# End of Locking variables and tools section
+#####################################################
+
+do-lock:
+	@${DO_NADA}
 
-# In this target there is no timeout, because if it is necessary to unlock dir then
-# this process has to wait until all other registered to lockf(1) operation processes do their stuff.
 do-unlock:
-	@lockf -k ${_parv_LOCK_FILE} ${RM} ${_parv_LOCK_FILE}
+	@${DO_NADA}
+


More information about the svn-soc-all mailing list