From 94b06f4a7da72fa07f4aa0536f80c6e65a7813f6 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 16 Oct 2011 21:24:17 +0200 Subject: [PATCH] When zone contents do not change, version number is not incremented Replaced direct calls to M4 from the Makefile by calling an auxiliary script (generated by m4/mkgenzone.m4), which calculates a MD5 hash of a (suitably normalized) zone file and compares it with a cached hash of the current version. The downside is that we run M4 twice on each changed zone. If it ever causes any harm, we can generate the zone once and move updating of the version number to the shell script, too. Based on a patch by Vaclav Ovsik. --- NEWS | 15 ++++++++------- TODO | 2 -- bin/nsconfig | 4 +++- m4/dnslib.m4 | 1 + m4/mkgenzone.m4 | 25 +++++++++++++++++++++++++ m4/mkmf.m4 | 10 ++++------ m4/nsc.m4 | 7 ++++++- 7 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 m4/mkgenzone.m4 diff --git a/NEWS b/NEWS index 8062980..a4da74d 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,3 @@ - o Added FORWARDING macro for generating forward-only zones. o Added BLACKHOLE macro for blackhole zones as per RFC 6303. Blackhole zones in example cf/domains updated to use this macro. @@ -7,25 +6,27 @@ appropriate options to BIND config file and include the part with the list of zones generated by NSC from there. This means that BIND_OPTIONS, FORWARD and SLAVE are gone. + o When contents of a zone do not change, the version number is + not incremented. -Version 3.1 [21-05-2008] +Version 3.1 [2008-05-21] o Fixes for compatibility problems with recent versions of GNU m4. o Added support for TXT, RP and SRV records. -Version 3.0.1 [22-11-2006] +Version 3.0.1 [2006-11-22] Fixed bugs in in the FORWARD and SLAVE macros, causing it to generate bogus output sometimes. -Version 3.0 [20-02-2005] +Version 3.0 [2005-02-20] One year of testing should be good enough, so releasing 2.99b as 3.0 with almost no changes. The only one is: o ZONE_OPTIONS macro added, allowing to add custom options to zones. -Version 2.99b [21-12-2003] +Version 2.99b [2003-12-21] This version has been almost rewritten from scratch. The syntax of configuration files is incompatible with the previous versions, @@ -40,7 +41,7 @@ Version 2.99b [21-12-2003] o Cleaned up names of all macros, the namespaces are now clearly defined. -Version 2.3 [27-06-2001] +Version 2.3 [2001-06-27] o Global parameters (hostmaster mail address etc.) can be set in cf/config now. @@ -48,7 +49,7 @@ Version 2.3 [27-06-2001] o Fixed bugs in convert script. o Generate $TTL to make new releases of bind happy. -Version 2.2 [11-09-1999] +Version 2.2 [1999-09-11] o Corrected localhost records. o Name-server restart command can be overriden (useful for setups diff --git a/TODO b/TODO index e0da11b..bf97c01 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ freebsd: don't use `-f' in hostname -if a zone doesn't change, don't bump the version -BIND9: options BIND9: `bak' must be owned by the bind user diff --git a/bin/nsconfig b/bin/nsconfig index c23ebc7..14d34ed 100755 --- a/bin/nsconfig +++ b/bin/nsconfig @@ -13,4 +13,6 @@ if [ ! -f $DOMAINS ] ; then fi $M4 m4/mkconf.m4 $DOMAINS >named.conf -$M4 -DM4=$M4 m4/mkmf.m4 $DOMAINS >Makefile +$M4 m4/mkmf.m4 $DOMAINS >Makefile +$M4 -DM4=$M4 m4/mkgenzone.m4 >bin/genzone +chmod +x bin/genzone diff --git a/m4/dnslib.m4 b/m4/dnslib.m4 index f6fc63c..9fc84fe 100644 --- a/m4/dnslib.m4 +++ b/m4/dnslib.m4 @@ -92,6 +92,7 @@ define(`CFDIR', `cf') define(`ZONEDIR', `zone') define(`BAKDIR', `bak') define(`VERSDIR', `ver') +define(`HASHDIR', `hash') define(`ROOTCACHE', `root.cache') define(`REFRESH', HOURS(8)) diff --git a/m4/mkgenzone.m4 b/m4/mkgenzone.m4 new file mode 100644 index 0000000..0d898f4 --- /dev/null +++ b/m4/mkgenzone.m4 @@ -0,0 +1,25 @@ +dnl ### +dnl ### NSC -- Zone Generating Script Builder +dnl ### (c) 2011 Martin Mares +dnl ### +include(m4/dnslib.m4) +changecom(REM) +divert(0)dnl +#!/bin/sh +# Please do not modify this script, it is automatically generated by m4/mkgenzone.m4 + +set -e +Z=`$'1 +shift +mkdir -p HASHDIR +CURRENT_HASH=$(M4 -DHASHING m4/nsc.m4 "$@" | md5sum | cut -d " " -f1) +PREV_HASH=$(if [ -s HASHDIR/$Z ] ; then cat HASHDIR/$Z ; fi) +if [ "X$CURRENT_HASH" = "X$PREV_HASH" ] ; then + echo "-- $Z: No changes" + touch ZONEDIR/$Z HASHDIR/$Z +else + M4 -DVERS=VERSDIR/$Z m4/nsc.m4 "$@" >ZONEDIR/$Z.new + mv ZONEDIR/$Z.new ZONEDIR/$Z + echo "** $Z: New version $(sed -e "s/^;;; VERSION: //; t; d" ZONEDIR/$Z)" + echo $CURRENT_HASH >HASHDIR/$Z +fi diff --git a/m4/mkmf.m4 b/m4/mkmf.m4 index fd4ca87..0f0b5f6 100644 --- a/m4/mkmf.m4 +++ b/m4/mkmf.m4 @@ -11,7 +11,7 @@ define(`PRIMARIES', `') define(`nsc_prepend_cf_one', ` 'CFDIR/`nsc_file_name($1)') define(`nsc_prepend_cf_multi', `nsc_iterate(`nsc_prepend_cf_one', $@)') define(`PRIMARY', `divert(0)ZONEDIR/nsc_file_name($1):nsc_prepend_cf_multi($@) $(DDEPS) - `$'(`M4') -DVERS=VERSDIR/nsc_file_name($1) `$'(NSC)nsc_prepend_cf_multi($@) >ZONEDIR/nsc_file_name($1) + @bin/genzone nsc_file_name($1)`'nsc_prepend_cf_multi($@) divert(-1) define(`PRIMARIES', PRIMARIES ZONEDIR/nsc_file_name($1)) @@ -37,10 +37,10 @@ divert(0)VERSDIR/.version: CFDIR/domains ROOTCACHE`'PRIMARIES`'ifdef(`NEED_BLACK ')dnl clean: - find BAKDIR ZONEDIR -maxdepth 1 -type f | xargs rm -f + find BAKDIR ZONEDIR HASHDIR -maxdepth 1 -type f | xargs rm -f clobber: clean - rm -f Makefile named.conf + rm -f Makefile named.conf bin/genzone distclean: clobber find VERSDIR -maxdepth 1 -type f | xargs rm -f @@ -53,9 +53,7 @@ divert(0)dnl `#' Please don't edit manually `#' -`M4'=M4 -NSC=m4/nsc.m4 -DDEPS=`$'(NSC) m4/dnslib.m4 cf/config +DDEPS=m4/nsc.m4 m4/dnslib.m4 cf/config all: VERSDIR/.version m4wrap(`nsc_cleanup') diff --git a/m4/nsc.m4 b/m4/nsc.m4 index 80d091e..224512d 100644 --- a/m4/nsc.m4 +++ b/m4/nsc.m4 @@ -8,6 +8,8 @@ include(m4/dnslib.m4) # Version number +ifdef(`HASHING', `define(`VERSION',`YYYYMMDDNN')', ` + ifdef(`VERS',`',`nsc_fatal_error(`VERS macro not defined')') define(TODAY_CODE, translit(esyscmd(`date +"%Y%m%d"'),` @@ -21,6 +23,8 @@ syscmd(echo >VERS "`define'(`LAST_TODAY_CODE',TODAY_CODE) `define'(`SUBVER_NUM', ifelse(eval(SUBVER_NUM > 99),1,`nsc_fatal_error(`Too many zone changes in a single day, you must tweak 'VERS` manually')') define(`VERSION',TODAY_CODE`'format(`%02d', SUBVER_NUM)) +') + # Record names define(nsc_set_name, `define(`CURRENT_NAME', nsc_corr_dot($1))define(`PRINT_NAME', CURRENT_NAME)') @@ -155,6 +159,7 @@ m4wrap(`nsc_cleanup') divert(0)dnl `;;;' Primary zone file -`;;;' Generated by NSCVER (nsc.m4) on CURRENT_DATE +`;;;' Generated by NSCVER (nsc.m4) on ifdef(`HASHING', ``CURRENT_DATE'', `CURRENT_DATE') `;;;' Please do not edit manually +`;;;' `VERSION': VERSION `' -- 2.39.2