Write files atomically in the microcode makefile.
authorTaylor R Campbell <campbell@mumble.net>
Mon, 30 Sep 2013 22:56:19 +0000 (22:56 +0000)
committerTaylor R Campbell <campbell@mumble.net>
Mon, 30 Sep 2013 22:56:21 +0000 (22:56 +0000)
Use a temporary file and rename it over the permanent one only if the
command succeeded.  That way, we don't leave truncated files around
on failure.

src/microcode/makegen/Makefile.in.in

index 94a89d14f629aed45481e57d8779f5c4f22529b3..2cf602cda484dd1cfc35ea4b121b2eb4463b8e48 100644 (file)
@@ -161,7 +161,8 @@ MAINTAINER_CLEAN_FILES = Makefile.in Makefile.deps liarc-vars liarc-rules \
        $(COMPILE) -o $@ -c $<
 
 .m4.s:
-       $(EXPAND) $< > $@
+       -rm -f $@.tmp
+       $(EXPAND) $< > $@.tmp && mv -f $@.tmp $@
 
 .s.o:
        $(ASSEMBLE) -o $@ $<
@@ -175,8 +176,8 @@ scheme: $(scheme_OBJECTS) $(scheme_DEPENDENCIES)
        $(LINK) $(scheme_LDFLAGS) $(scheme_OBJECTS) $(scheme_LIBS)
 
 usrdef.c: $(STD_SOURCES) findprim Makefile
-       -rm -f $@
-       ./findprim $(STD_SOURCES) > usrdef.c
+       -rm -f $@.tmp
+       ./findprim $(STD_SOURCES) > $@.tmp && mv -f $@.tmp $@
 
 findprim: $(findprim_OBJECTS) $(findprim_DEPENDENCIES)
        -rm -f $@