Diff: Fix race condition with parallel `mkdir -p's

Warwick Harvey wharvey at cs.monash.edu.au
Mon Mar 15 11:37:29 AEDT 1999


Fergus has already reviewed this, so I'm committing after sending this mail.

Estimated hours taken: 0.5

boehm_gc/Mmakefile:
browser/Mmakefile:
compiler/Mmakefile:
doc/Mmakefile:
library/Mmakefile:
runtime/Mmakefile:
scripts/Mmakefile:
	Separated out all the commands to create installation directories
	into a single target in each Mmakefile, upon which all targets which
	used to create directories depend.  This avoids a race condition
	with parallel installs into a new directory tree, whereby two or
	more `mkdir -p' commands simultaneously try to create the same
	missing path component, resulting in all but one failing.

	Note that this can result in directories being created during 
	install that would not have been otherwise.

Index: boehm_gc/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/boehm_gc/Mmakefile,v
retrieving revision 1.6
diff -u -r1.6 Mmakefile
--- Mmakefile	1998/04/02 13:22:59	1.6
+++ Mmakefile	1999/03/15 00:21:44
@@ -70,19 +70,21 @@
 endif
 #---------------------------------------------------------------------------
--#
 
-
-.PHONY: install_headers
-install_headers:
-	-[ -d $(INSTALL_INC_DIR) ] || mkdir -p $(INSTALL_INC_DIR)
+.PHONY: install_dirs
+install_dirs:
+	#-[ -d $(INSTALL_INC_DIR) ] || mkdir -p $(INSTALL_INC_DIR)
 	-[ -d $(INSTALL_INC_DIR)/private ] || \
 		mkdir -p $(INSTALL_INC_DIR)/private
+	-[ -d $(INSTALL_MERC_GC_LIB_DIR) ] || \
+		mkdir -p $(INSTALL_MERC_GC_LIB_DIR)
+
+.PHONY: install_headers
+install_headers: install_dirs
 	cp $(HEADERS) $(INSTALL_INC_DIR)
 	cp $(PRIVATE_HEADERS) $(INSTALL_INC_DIR)/private
 
 .PHONY: install_lib
-install_lib: libgc$(PROF).a libgc$(PROF).$(EXT_FOR_SHARED_LIB)
-	-[ -d $(INSTALL_MERC_GC_LIB_DIR) ] || \
-		mkdir -p $(INSTALL_MERC_GC_LIB_DIR)
+install_lib: libgc$(PROF).a libgc$(PROF).$(EXT_FOR_SHARED_LIB) install_dirs
 	cp `vpath_find libgc$(PROF).a libgc$(PROF).$(EXT_FOR_SHARED_LIB)` \
 		$(INSTALL_MERC_GC_LIB_DIR) \
 
Index: browser/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/Mmakefile,v
retrieving revision 1.2
diff -u -r1.2 Mmakefile
--- Mmakefile	1998/10/25 07:16:36	1.2
+++ Mmakefile	1999/03/15 00:21:44
@@ -174,15 +174,18 @@
 .PHONY: install
 install: install_init install_library
 
-.PHONY: install_init
-install_init: $(BROWSER_LIB_NAME).init
+.PHONY: install_dirs
+install_dirs:
 	[ -d $(INSTALL_MODULE_DIR) ] || mkdir -p $(INSTALL_MODULE_DIR)
+	[ -d $(INSTALL_MERC_LIB_DIR) ] || mkdir -p $(INSTALL_MERC_LIB_DIR)
+
+.PHONY: install_init
+install_init: $(BROWSER_LIB_NAME).init install_dirs
 	cp `vpath_find $(BROWSER_LIB_NAME).init` $(INSTALL_MODULE_DIR)
 
 .PHONY: install_library
 install_library: lib$(BROWSER_LIB_NAME).a \
-		lib$(BROWSER_LIB_NAME).$(EXT_FOR_SHARED_LIB)
-	[ -d $(INSTALL_MERC_LIB_DIR) ] || mkdir -p $(INSTALL_MERC_LIB_DIR)
+		lib$(BROWSER_LIB_NAME).$(EXT_FOR_SHARED_LIB) install_dirs
 	cp `vpath_find lib$(BROWSER_LIB_NAME).a \
 		lib$(BROWSER_LIB_NAME).$(EXT_FOR_SHARED_LIB)` \
 		$(INSTALL_MERC_LIB_DIR)
Index: compiler/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Mmakefile,v
retrieving revision 1.14
diff -u -r1.14 Mmakefile
--- Mmakefile	1998/10/02 20:12:11	1.14
+++ Mmakefile	1999/03/15 00:21:44
@@ -160,22 +160,25 @@
 .PHONY: install_sicstus
 install_sicstus: install_compiler_sicstus
 
-.PHONY: install_compiler
-install_compiler: mercury_compile
+.PHONY: install_dirs
+install_dirs:
 	-[ -d $(INSTALL_MERC_BIN_DIR) ] || mkdir -p $(INSTALL_MERC_BIN_DIR)
+	-[ -d $(INSTALL_NU_ARCH_DIR) ] || mkdir -p $(INSTALL_NU_ARCH_DIR) 
+	-[ -d $(INSTALL_SP_ARCH_DIR) ] || mkdir -p $(INSTALL_SP_ARCH_DIR) 
+
+.PHONY: install_compiler
+install_compiler: mercury_compile install_dirs
 	cp `vpath_find mercury_compile` $(INSTALL_MERC_BIN_DIR)
 
 .PHONY: install_compiler_nu
-install_compiler_nu: mercury_compile.nu
-	-[ -d $(INSTALL_NU_ARCH_DIR) ] || mkdir -p $(INSTALL_NU_ARCH_DIR) 
+install_compiler_nu: mercury_compile.nu install_dirs
 	sed "s^`pwd`^$(INSTALL_NU_ARCH_DIR)^g" `vpath_find mercury_compile.nu` \
 		> $(INSTALL_NU_ARCH_DIR)/mercury_compile.nu
 	-chmod +x $(INSTALL_NU_ARCH_DIR)/mercury_compile.nu
 	cp `vpath_find mercury_compile.nu.save` $(INSTALL_NU_ARCH_DIR)
 
 .PHONY: install_compiler_sicstus
-install_compiler_sicstus: mercury_compile.sicstus
-	-[ -d $(INSTALL_SP_ARCH_DIR) ] || mkdir -p $(INSTALL_SP_ARCH_DIR) 
+install_compiler_sicstus: mercury_compile.sicstus install_dirs
 	cp `vpath_find mercury_compile.sicstus` $(INSTALL_SP_ARCH_DIR)
 
 #---------------------------------------------------------------------------
--#
Index: doc/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/Mmakefile,v
retrieving revision 1.15
diff -u -r1.15 Mmakefile
--- Mmakefile	1999/02/21 10:09:46	1.15
+++ Mmakefile	1999/03/15 00:21:44
@@ -172,9 +172,20 @@
 install: install_info install_html install_dvi install_manpages 
install_mdb_doc
 	# install_text install_ps
 
-.PHONY: install_info
-install_info: info
+.PHONY: install_dirs
+install_dirs:
 	-[ -d $(INSTALL_INFO_DIR) ] || mkdir -p $(INSTALL_INFO_DIR)
+	-[ -d $(INSTALL_HTML_DIR) ] || mkdir -p $(INSTALL_HTML_DIR)
+	-[ -d $(INSTALL_DVI_DIR) ] || mkdir -p $(INSTALL_DVI_DIR)
+	-[ -d $(INSTALL_TEXT_DIR) ] || mkdir -p $(INSTALL_TEXT_DIR)
+	-[ -d $(INSTALL_PS_DIR) ] || mkdir -p $(INSTALL_PS_DIR)
+	-[ -d $(INSTALL_MAN_DIR)/man1 ] || \
+		mkdir -p $(INSTALL_MAN_DIR)/man1
+	-[ -d $(INSTALL_MDB_DOC_DIR) ] || mkdir -p $(INSTALL_MDB_DOC_DIR)
+	-[ -d $(INSTALL_WEBPAGE_DIR) ] || mkdir -p $(INSTALL_WEBPAGE_DIR)
+
+.PHONY: install_info
+install_info: info install_dirs
 	-cp *.info* $(INSTALL_INFO_DIR)
 	# Update the .../info/dir file.
 	-if [ -x "$(INSTALL_INFO)" ]; then				\
@@ -182,34 +193,27 @@
 	fi
 
 .PHONY: install_html
-install_html: html
-	-[ -d $(INSTALL_HTML_DIR) ] || mkdir -p $(INSTALL_HTML_DIR)
+install_html: html install_dirs
 	cp *.html $(INSTALL_HTML_DIR)
 
 .PHONY: install_dvi
-install_dvi: dvi
-	-[ -d $(INSTALL_DVI_DIR) ] || mkdir -p $(INSTALL_DVI_DIR)
+install_dvi: dvi install_dirs
 	cp *.dvi $(INSTALL_DVI_DIR)
 
 .PHONY: install_text
-install_text: text
-	-[ -d $(INSTALL_TEXT_DIR) ] || mkdir -p $(INSTALL_TEXT_DIR)
+install_text: text install_dirs
 	cp *.txt $(INSTALL_TEXT_DIR)
 
 .PHONY: install_ps
-install_ps: ps
-	-[ -d $(INSTALL_PS_DIR) ] || mkdir -p $(INSTALL_PS_DIR)
+install_ps: ps install_dirs
 	cp *.ps $(INSTALL_PS_DIR)
 
 .PHONY: install_manpages
-install_manpages: manpages
-	-[ -d $(INSTALL_MAN_DIR)/man1 ] || \
-		mkdir -p $(INSTALL_MAN_DIR)/man1
+install_manpages: manpages install_dirs
 	cp *.1 $(INSTALL_MAN_DIR)/man1
 
 .PHONY: install_mdb_doc
-install_mdb_doc: mdb_doc
-	-[ -d $(INSTALL_MDB_DOC_DIR) ] || mkdir -p $(INSTALL_MDB_DOC_DIR)
+install_mdb_doc: mdb_doc install_dirs
 	cp mdb_doc $(INSTALL_MDB_DOC_DIR)
 
 # The uninstall rule here only removes the info files; the others
@@ -225,8 +229,7 @@
 # INSTALL_WEBPAGE_DIR).
 
 .PHONY: install_webpage
-install_webpage: library-chapters.texi split_html ps 
-	[ -d $(INSTALL_WEBPAGE_DIR) ] || mkdir -p $(INSTALL_WEBPAGE_DIR)
+install_webpage: library-chapters.texi split_html ps  install_dirs
 	cp *.ps $(INSTALL_WEBPAGE_DIR)
 	for file in $(INSTALL_WEBPAGE_DIR)/*.ps ; do \
 		gzip -f -9 $$file ; \
cvs server: Diffing extras/odbc
Index: library/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/library/Mmakefile,v
retrieving revision 1.34
diff -u -r1.34 Mmakefile
--- Mmakefile	1998/09/29 05:10:42	1.34
+++ Mmakefile	1999/03/15 00:21:44
@@ -330,10 +330,20 @@
 .PHONY: install_mercury
 install_mercury: install_ints install_init install_library
 
+.PHONY: install_dirs
+install_dirs:
+	#-[ -d $(INSTALL_INT_DIR) ] || mkdir -p $(INSTALL_INT_DIR)
+	-[ -d $(INSTALL_INT_DIR)/Mercury ] || \
+		mkdir -p $(INSTALL_INT_DIR)/Mercury
+	-[ -d $(INSTALL_MODULE_DIR) ] || mkdir -p $(INSTALL_MODULE_DIR)
+	-[ -d $(INSTALL_MERC_LIB_DIR) ] || mkdir -p $(INSTALL_MERC_LIB_DIR)
+	-[ -d $(INSTALL_NU_DIR) ] || mkdir -p $(INSTALL_NU_DIR)
+	-[ -d $(INSTALL_NU_ARCH_DIR) ] || mkdir -p $(INSTALL_NU_ARCH_DIR)
+	-[ -d $(INSTALL_SP_ARCH_DIR) ] || mkdir -p $(INSTALL_SP_ARCH_DIR)
+
 .PHONY: install_ints
 install_ints: $(library.ints) $(library.int3s) \
-		$(library.opts) $(library.trans_opts)
-	[ -d $(INSTALL_INT_DIR) ] || mkdir -p $(INSTALL_INT_DIR)
+		$(library.opts) $(library.trans_opts) install_dirs
 	for file in $(library.ints) $(library.int3s) \
 			$(library.opts) $(library.trans_opts); \
 	do \
@@ -346,16 +356,13 @@
 		fi; \
 	done
 	# The following is needed to support the `--use-subdirs' option
-	[ -d $(INSTALL_INT_DIR)/Mercury ] || \
-		mkdir -p $(INSTALL_INT_DIR)/Mercury
 	for dir in ints int2s int3s opts trans_opts; do \
 		rm -f $(INSTALL_INT_DIR)/Mercury/$$dir; \
 		ln -s .. $(INSTALL_INT_DIR)/Mercury/$$dir; \
 	done
 
 .PHONY: install_init
-install_init: $(STD_LIB_NAME).init
-	[ -d $(INSTALL_MODULE_DIR) ] || mkdir -p $(INSTALL_MODULE_DIR)
+install_init: $(STD_LIB_NAME).init install_dirs
 	cp `vpath_find $(STD_LIB_NAME).init` $(INSTALL_MODULE_DIR)
 	# "$(STD_LIB_NAME).init" used to be called "library.init" or
 	# "libmercury.init". If there is still a version with an old name
@@ -365,8 +372,8 @@
 		$(INSTALL_MODULE_DIR)/libmercury.init
 
 .PHONY: install_library
-install_library: lib$(STD_LIB_NAME).a lib$(STD_LIB_NAME).$(EXT_FOR_SHARED_LI
B)
-	[ -d $(INSTALL_MERC_LIB_DIR) ] || mkdir -p $(INSTALL_MERC_LIB_DIR)
+install_library: lib$(STD_LIB_NAME).a \
+		lib$(STD_LIB_NAME).$(EXT_FOR_SHARED_LIB) install_dirs
 	cp `vpath_find lib$(STD_LIB_NAME).a \
 		lib$(STD_LIB_NAME).$(EXT_FOR_SHARED_LIB)` \
 		$(INSTALL_MERC_LIB_DIR)
@@ -374,8 +381,7 @@
 # library.split.a is a version of lib$(STD_LIB_NAME).a that has been 
compiled
 # with `--split-c-files'.
 .PHONY: install_split_library
-install_split_library: library.split.a
-	[ -d $(INSTALL_MERC_LIB_DIR) ] || mkdir -p $(INSTALL_MERC_LIB_DIR)
+install_split_library: library.split.a install_dirs
 	cp `vpath_find library.split.a` \
 		$(INSTALL_MERC_LIB_DIR)/lib$(STD_LIB_NAME).a
 
@@ -386,18 +392,15 @@
 install_library_nu: $(library.nos) $(NU_LIBRARY_NOS) \
 			$(NU_OVERRIDING_LIBRARY_NOS) \
 			$(nos_subdir)error.no $(nos_subdir)debug.no \
-			$(nos_subdir)portray.no nc_builtin.nl
-	[ -d $(INSTALL_NU_DIR) ] || mkdir -p $(INSTALL_NU_DIR)
+			$(nos_subdir)portray.no nc_builtin.nl install_dirs
 	cp `vpath_find nc_builtin.nl` $(INSTALL_NU_DIR)
-	[ -d $(INSTALL_NU_ARCH_DIR) ] || mkdir -p $(INSTALL_NU_ARCH_DIR)
 	cp `vpath_find $(library.nos) $(NU_LIBRARY_NOS) \
 		$(NU_OVERRIDING_LIBRARY_NOS) \
 		$(nos_subdir)error.no $(nos_subdir)debug.no \
 		$(nos_subdir)portray.no` $(INSTALL_NU_ARCH_DIR)
 
 .PHONY: install_interpreter_nu
-install_interpreter_nu: library.nu
-	[ -d $(INSTALL_NU_ARCH_DIR) ] || mkdir -p $(INSTALL_NU_ARCH_DIR)
+install_interpreter_nu: library.nu install_dirs
 	sed "s^`pwd`^$(INSTALL_NU_ARCH_DIR)^g" `vpath_find library.nu` \
 		> $(INSTALL_NU_ARCH_DIR)/library.nu
 	-chmod +x $(INSTALL_NU_ARCH_DIR)/library.nu
@@ -407,13 +410,11 @@
 install_sicstus: install_interpreter_sicstus install_sicstus_compile
 
 .PHONY: install_interpreter_sicstus
-install_interpreter_sicstus: library.sicstus.debug
-	[ -d $(INSTALL_SP_ARCH_DIR) ] || mkdir -p $(INSTALL_SP_ARCH_DIR)
+install_interpreter_sicstus: library.sicstus.debug install_dirs
 	cp `vpath_find library.sicstus.debug` $(INSTALL_SP_ARCH_DIR)
 
 .PHONY: install_sicstus_compile
-install_sicstus_compile: sicstus_compile
-	[ -d $(INSTALL_SP_ARCH_DIR) ] || mkdir -p $(INSTALL_SP_ARCH_DIR)
+install_sicstus_compile: sicstus_compile install_dirs
 	cp `vpath_find sicstus_compile` $(INSTALL_SP_ARCH_DIR)
 
 else
Index: runtime/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/Mmakefile,v
retrieving revision 1.43
diff -u -r1.43 Mmakefile
--- Mmakefile	1998/12/15 00:22:08	1.43
+++ Mmakefile	1999/03/15 00:21:44
@@ -264,17 +264,21 @@
 .PHONY: install
 install: install_headers install_init install_lib
 
-.PHONY: install_headers
-install_headers: $(HDRS) $(MACHHDRS) $(LIB_GLOBALS_H)
+.PHONY: install_dirs
+install_dirs:
 	-[ -d $(INSTALL_INC_DIR)/machdeps ] || \
 		mkdir -p $(INSTALL_INC_DIR)/machdeps
+	-[ -d $(INSTALL_MODULE_DIR) ] || mkdir -p $(INSTALL_MODULE_DIR)
+	-[ -d $(INSTALL_MERC_LIB_DIR) ] || mkdir -p $(INSTALL_MERC_LIB_DIR)
+
+.PHONY: install_headers
+install_headers: $(HDRS) $(MACHHDRS) $(LIB_GLOBALS_H) install_dirs
 	cp `vpath_find $(HDRS) $(LIB_GLOBALS_H)` $(INSTALL_INC_DIR)
 	chmod u+w $(INSTALL_INC_DIR)/mercury_conf.h
 	cp `vpath_find $(MACHHDRS)` $(INSTALL_INC_DIR)/machdeps
 
 .PHONY: install_init
-install_init: $(RT_LIB_NAME).init
-	-[ -d $(INSTALL_MODULE_DIR) ] || mkdir -p $(INSTALL_MODULE_DIR)
+install_init: $(RT_LIB_NAME).init install_dirs
 	cp `vpath_find $(RT_LIB_NAME).init` $(INSTALL_MODULE_DIR)
 	# "$(RT_LIB_NAME).init" used to be called "runtime.init".
 	# If there is still a version with an old name lying around,
@@ -282,8 +286,8 @@
 	rm -f $(INSTALL_MODULE_DIR)/runtime.init
 
 .PHONY: install_lib
-install_lib: lib$(RT_LIB_NAME).a lib$(RT_LIB_NAME).$(EXT_FOR_SHARED_LIB)
-	-[ -d $(INSTALL_MERC_LIB_DIR) ] || mkdir -p $(INSTALL_MERC_LIB_DIR)
+install_lib: lib$(RT_LIB_NAME).a lib$(RT_LIB_NAME).$(EXT_FOR_SHARED_LIB) \
+		install_dirs
 	cp `vpath_find lib$(RT_LIB_NAME).a \
 		lib$(RT_LIB_NAME).$(EXT_FOR_SHARED_LIB)` \
 		$(INSTALL_MERC_LIB_DIR)
cvs server: Diffing samples/c_interface/mercury_calls_cplusplus
Index: scripts/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/Mmakefile,v
retrieving revision 1.12
diff -u -r1.12 Mmakefile
--- Mmakefile	1998/12/21 11:33:59	1.12
+++ Mmakefile	1999/03/15 00:21:45
@@ -49,15 +49,20 @@
 install: install_mmake install_scripts install_debugger_scripts
 install: $(INSTALL_NUPROLOG) $(INSTALL_SICSTUS)
 
-.PHONY: install_mmake
-install_mmake: Mmake.vars Mmake.rules
+.PHONY: install_dirs
+install_dirs:
+	[ -d $(INSTALL_BINDIR) ] || mkdir -p $(INSTALL_BINDIR)
 	[ -d $(INSTALL_LIBDIR)/mmake ] || mkdir -p $(INSTALL_LIBDIR)/mmake
+	[ -d $(INSTALL_LIBDIR)/mdb ] || mkdir -p $(INSTALL_LIBDIR)/mdb
+	[ -d $(INSTALL_ELISP_DIR) ] || mkdir -p $(INSTALL_ELISP_DIR)
+
+.PHONY: install_mmake
+install_mmake: Mmake.vars Mmake.rules install_dirs
 	rm -f $(INSTALL_LIBDIR)/mmake/Mmake.vars
 	cp `vpath_find Mmake.vars Mmake.rules` $(INSTALL_LIBDIR)/mmake
 
 .PHONY: install_scripts
-install_scripts: $(SCRIPTS)
-	[ -d $(INSTALL_BINDIR) ] || mkdir -p $(INSTALL_BINDIR)
+install_scripts: $(SCRIPTS) install_dirs
 	# we remove the installed `mmake' script before (re)installing it
 	# to avoid overwriting the script while it is running
 	-rm -f $(INSTALL_BINDIR)/mmake
@@ -67,26 +72,22 @@
 	done
 
 .PHONY: install_emacs_scripts
-install_emacs_scripts: $(EMACS_SCRIPTS) install_libdir
-	[ -d $(INSTALL_ELISP_DIR) ] || mkdir -p $(INSTALL_ELISP_DIR)
+install_emacs_scripts: $(EMACS_SCRIPTS) install_libdir install_dirs
 	cp $(EMACS_SCRIPTS) $(INSTALL_ELISP_DIR)
 
 .PHONY: install_debugger_scripts
-install_debugger_scripts: $(DEBUGGER_SCRIPTS)
-	[ -d $(INSTALL_LIBDIR)/mdb ] || mkdir -p $(INSTALL_LIBDIR)/mdb
+install_debugger_scripts: $(DEBUGGER_SCRIPTS) install_dirs
 	cp $(DEBUGGER_SCRIPTS) $(INSTALL_LIBDIR)/mdb 
 
 .PHONY: install_nuprolog
-install_nuprolog: $(NUPROLOG_SCRIPTS)
-	[ -d $(INSTALL_BINDIR) ] || mkdir -p $(INSTALL_BINDIR)
+install_nuprolog: $(NUPROLOG_SCRIPTS) install_dirs
 	cp $(NUPROLOG_SCRIPTS) $(INSTALL_BINDIR) 
 	for file in $(NUPROLOG_SCRIPTS); do \
 		chmod u+w $(INSTALL_BINDIR)/$$file ;\
 	done
 
 .PHONY: install_sicstus
-install_sicstus: $(SICSTUS_SCRIPTS)
-	[ -d $(INSTALL_BINDIR) ] || mkdir -p $(INSTALL_BINDIR)
+install_sicstus: $(SICSTUS_SCRIPTS) install_dirs
 	cp $(SICSTUS_SCRIPTS) $(INSTALL_BINDIR) 
 	for file in $(SICSTUS_SCRIPTS); do \
 		chmod u+w $(INSTALL_BINDIR)/$$file ;\





More information about the developers mailing list