dovecot-2.2: Makefile: Avoid make race conditions when generatin...

dovecot at dovecot.org dovecot at dovecot.org
Fri Mar 13 13:07:08 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/d592417ec815
changeset: 18344:d592417ec815
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Mar 13 15:06:10 2015 +0200
description:
Makefile: Avoid make race conditions when generating files that are used as dependencies.
The file creation needs to be atomic, otherwise another process can start
trying to use an unfinished file. So we first create .tmp file and then mv
it into the final one.

diffstat:

 src/config/Makefile.am               |   2 +-
 src/lib-dict/Makefile.am             |  33 ++++++++++++++++---------------
 src/lib-sql/Makefile.am              |  17 ++++++++-------
 src/lib-storage/register/Makefile.am |  38 ++++++++++++++++++-----------------
 src/lib/Makefile.am                  |   2 +-
 src/plugins/quota/Makefile.am        |   5 ++-
 6 files changed, 51 insertions(+), 46 deletions(-)

diffs (193 lines):

diff -r 308a97126244 -r d592417ec815 src/config/Makefile.am
--- a/src/config/Makefile.am	Thu Mar 12 19:39:03 2015 +0200
+++ b/src/config/Makefile.am	Fri Mar 13 15:06:10 2015 +0200
@@ -55,7 +55,7 @@
 	config-request.h
 
 all-settings.c: $(SETTING_FILES) $(top_srcdir)/src/config/settings-get.pl
-	$(top_srcdir)/src/config/settings-get.pl $(SETTING_FILES) > all-settings.c || rm -f all-settings.c
+	$(top_srcdir)/src/config/settings-get.pl $(SETTING_FILES) > all-settings.c.tmp && mv all-settings.c.tmp all-settings.c
 
 EXTRA_DIST = \
 	config-settings.c \
diff -r 308a97126244 -r d592417ec815 src/lib-dict/Makefile.am
--- a/src/lib-dict/Makefile.am	Thu Mar 12 19:39:03 2015 +0200
+++ b/src/lib-dict/Makefile.am	Fri Mar 13 15:06:10 2015 +0200
@@ -46,34 +46,35 @@
 pkginc_lib_HEADERS = $(headers)
 
 dict-drivers-register.c: Makefile $(top_builddir)/config.h
-	rm -f $@
-	echo '/* this file automatically generated by Makefile */' >$@
-	echo '#include "lib.h"' >>$@
-	echo '#include "dict.h"' >>$@
-	echo '#include "dict-sql.h"' >>$@
+	rm -f $@.tmp
+	echo '/* this file automatically generated by Makefile */' >$@.tmp
+	echo '#include "lib.h"' >>$@.tmp
+	echo '#include "dict.h"' >>$@.tmp
+	echo '#include "dict-sql.h"' >>$@.tmp
 	for i in $(dict_drivers) null; do \
 	  if [ "$${i}" != "null" ]; then \
-	        echo "extern struct dict dict_driver_$${i};" >>$@ ; \
+	        echo "extern struct dict dict_driver_$${i};" >>$@.tmp ; \
 	  fi; \
 	done
-	echo 'void dict_drivers_register_all(void) {' >>$@
-	echo 'dict_drivers_register_builtin();' >>$@
-	echo 'dict_sql_register();' >>$@
+	echo 'void dict_drivers_register_all(void) {' >>$@.tmp
+	echo 'dict_drivers_register_builtin();' >>$@.tmp
+	echo 'dict_sql_register();' >>$@.tmp
 	for i in $(dict_drivers) null; do \
 	  if [ "$${i}" != "null" ]; then \
-	        echo "dict_driver_register(&dict_driver_$${i});" >>$@ ; \
+	        echo "dict_driver_register(&dict_driver_$${i});" >>$@.tmp ; \
 	  fi; \
 	done
-	echo '}' >>$@
-	echo 'void dict_drivers_unregister_all(void) {' >>$@
-	echo 'dict_drivers_unregister_builtin();' >>$@
-	echo 'dict_sql_unregister();' >>$@
+	echo '}' >>$@.tmp
+	echo 'void dict_drivers_unregister_all(void) {' >>$@.tmp
+	echo 'dict_drivers_unregister_builtin();' >>$@.tmp
+	echo 'dict_sql_unregister();' >>$@.tmp
 	for i in $(dict_drivers) null; do \
 	  if [ "$${i}" != "null" ]; then \
-	        echo "dict_driver_unregister(&dict_driver_$${i});" >>$@ ; \
+	        echo "dict_driver_unregister(&dict_driver_$${i});" >>$@.tmp ; \
 	  fi; \
 	done
-	echo '}' >>$@
+	echo '}' >>$@.tmp
+	mv $@.tmp $@
 
 distclean-generic:
 	rm -f Makefile dict-drivers-register.c
diff -r 308a97126244 -r d592417ec815 src/lib-sql/Makefile.am
--- a/src/lib-sql/Makefile.am	Thu Mar 12 19:39:03 2015 +0200
+++ b/src/lib-sql/Makefile.am	Fri Mar 13 15:06:10 2015 +0200
@@ -92,26 +92,27 @@
 pkginc_lib_HEADERS = $(headers)
 
 sql-drivers-register.c: Makefile
-	rm -f $@
-	echo '/* this file automatically generated by Makefile */' >$@
-	echo '#include "lib.h"' >>$@
-	echo '#include "sql-api.h"' >>$@
+	rm -f $@.tmp
+	echo '/* this file automatically generated by Makefile */' >$@.tmp
+	echo '#include "lib.h"' >>$@.tmp
+	echo '#include "sql-api.h"' >>$@.tmp
 if ! SQL_PLUGINS
 	for i in $(sql_drivers) null; do \
 	  if [ "$${i}" != "null" ]; then \
-	        echo "extern struct sql_db driver_$${i}_db;" >>$@ ; \
+	        echo "extern struct sql_db driver_$${i}_db;" >>$@.tmp ; \
 	  fi; \
 	done
 endif
-	echo 'void sql_drivers_register_all(void) {' >>$@
+	echo 'void sql_drivers_register_all(void) {' >>$@.tmp
 if ! SQL_PLUGINS
 	for i in $(sql_drivers) null; do \
 	  if [ "$${i}" != "null" ]; then \
-	        echo "sql_driver_register(&driver_$${i}_db);" >>$@ ; \
+	        echo "sql_driver_register(&driver_$${i}_db);" >>$@.tmp ; \
 	  fi; \
 	done
 endif
-	echo '}' >>$@
+	echo '}' >>$@.tmp
+	mv $@.tmp $@
 
 if SQL_PLUGINS
 install-exec-local:
diff -r 308a97126244 -r d592417ec815 src/lib-storage/register/Makefile.am
--- a/src/lib-storage/register/Makefile.am	Thu Mar 12 19:39:03 2015 +0200
+++ b/src/lib-storage/register/Makefile.am	Fri Mar 13 15:06:10 2015 +0200
@@ -5,34 +5,36 @@
 mailbox_list_drivers = @mailbox_list_drivers@
 
 mail-storage-register.c: Makefile
-	rm -f $@
-	echo '/* this file automatically generated by Makefile */' >$@
-	echo '#include "lib.h"' >>$@
-	echo '#include "mail-storage.h"' >>$@
+	rm -f $@.tmp
+	echo '/* this file automatically generated by Makefile */' >$@.tmp
+	echo '#include "lib.h"' >>$@.tmp
+	echo '#include "mail-storage.h"' >>$@.tmp
 	for i in $(mail_storages) ; do \
-		echo "extern struct mail_storage $${i}_storage;" >>$@ ; \
+		echo "extern struct mail_storage $${i}_storage;" >>$@.tmp ; \
 	done
-	echo 'void mail_storage_register_all(void) {' >>$@
+	echo 'void mail_storage_register_all(void) {' >>$@.tmp
 	for i in $(mail_storages) ; do \
-		echo "mail_storage_class_register(&$${i}_storage);" >>$@ ; \
+		echo "mail_storage_class_register(&$${i}_storage);" >>$@.tmp ; \
 	done
-	echo '}' >>$@
+	echo '}' >>$@.tmp
+	mv $@.tmp $@
 
 mailbox-list-register.c: Makefile
-	rm -f $@
-	echo '/* this file automatically generated by Makefile */' >$@
-	echo '#include "lib.h"' >>$@
-	echo '#include "mailbox-list.h"' >>$@
+	rm -f $@.tmp
+	echo '/* this file automatically generated by Makefile */' >$@.tmp
+	echo '#include "lib.h"' >>$@.tmp
+	echo '#include "mailbox-list.h"' >>$@.tmp
 	for i in $(mailbox_list_drivers) ; do \
-		echo "extern struct mailbox_list $${i}_mailbox_list;" >>$@ ; \
+		echo "extern struct mailbox_list $${i}_mailbox_list;" >>$@.tmp ; \
 	done
-	echo "void mailbox_list_index_init(void);" >>$@
-	echo 'void mailbox_list_register_all(void) {' >>$@
+	echo "void mailbox_list_index_init(void);" >>$@.tmp
+	echo 'void mailbox_list_register_all(void) {' >>$@.tmp
 	for i in $(mailbox_list_drivers) ; do \
-		echo "mailbox_list_register(&$${i}_mailbox_list);" >>$@ ; \
+		echo "mailbox_list_register(&$${i}_mailbox_list);" >>$@.tmp ; \
 	done
-	echo "mailbox_list_index_init();" >>$@
-	echo '}' >>$@
+	echo "mailbox_list_index_init();" >>$@.tmp
+	echo '}' >>$@.tmp
+	mv $@.tmp $@
 
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib \
diff -r 308a97126244 -r d592417ec815 src/lib/Makefile.am
--- a/src/lib/Makefile.am	Thu Mar 12 19:39:03 2015 +0200
+++ b/src/lib/Makefile.am	Fri Mar 13 15:06:10 2015 +0200
@@ -8,7 +8,7 @@
 	test -f UnicodeData.txt || wget http://www.unicode.org/Public/UNIDATA/UnicodeData.txt
 
 $(srcdir)/unicodemap.c: unicodemap.pl UnicodeData.txt
-	perl $(srcdir)/unicodemap.pl < UnicodeData.txt > $@
+	perl $(srcdir)/unicodemap.pl < UnicodeData.txt > $@.tmp && mv $@.tmp $@
 
 liblib_la_SOURCES = \
 	abspath.c \
diff -r 308a97126244 -r d592417ec815 src/plugins/quota/Makefile.am
--- a/src/plugins/quota/Makefile.am	Thu Mar 12 19:39:03 2015 +0200
+++ b/src/plugins/quota/Makefile.am	Fri Mar 13 15:06:10 2015 +0200
@@ -83,10 +83,11 @@
 	  sed -e 's/IXDR_PUT/(void)IXDR_PUT/g' \
 	    -e 's,/usr/include/rpcsvc/rquota.h,rquota.h,' \
 	    -e 's/int32_t \*buf/int32_t *buf ATTR_UNUSED/' \
-	    -e 's/^static char rcsid.*//' ) > rquota_xdr.c
+	    -e 's/^static char rcsid.*//' ) > rquota_xdr.c.tmp; \
+	mv rquota_xdr.c.tmp rquota_xdr.c
 
 rquota.h: Makefile $(RQUOTA_X)
-	$(RPCGEN) -h $(RQUOTA_X) > rquota.h
+	$(RPCGEN) -h $(RQUOTA_X) > rquota.h.tmp && mv rquota.h.tmp rquota.h
 
 quota-fs.lo: rquota.h
 


More information about the dovecot-cvs mailing list