INN commit: trunk (3 files)

INN Commit rra at isc.org
Tue Aug 16 13:59:22 UTC 2011


    Date: Tuesday, August 16, 2011 @ 06:59:21
  Author: iulius
Revision: 9341

cnfsstat:  reload configuration files when modified

cnfsstat now reloads storage.conf and cycbuff.conf if they have been modified
since the last iteration of the script (started with the "-l" flag).
Otherwise, the new configuration is not taken into account by a "ctlinnd xexec"
command; only rc.news starts cnfsstat.

Also change the "Cannot open CycBuff Conffile" message because it is not
always true.  The message can be logged when an error occurs during the
parsing of the file.  Sometimes, even when the parsing was incorrect,
the file was accepted.  This behaviour is also fixed, and the file is
refused at cnfsstat startup.

Modified:
  trunk/doc/pod/cnfsstat.pod
  trunk/doc/pod/news.pod
  trunk/frontends/cnfsstat.in

-----------------------+
 doc/pod/cnfsstat.pod  |    4 +++
 doc/pod/news.pod      |   10 +++++++++
 frontends/cnfsstat.in |   53 ++++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 63 insertions(+), 4 deletions(-)

Modified: doc/pod/cnfsstat.pod
===================================================================
--- doc/pod/cnfsstat.pod	2011-08-16 13:50:19 UTC (rev 9340)
+++ doc/pod/cnfsstat.pod	2011-08-16 13:59:21 UTC (rev 9341)
@@ -38,6 +38,10 @@
 and only exits if an error occurs.  When unspecified, the default interval
 is C<600> seconds.
 
+At each iteration, B<cnfsstat> checks whether the F<cycbuff.conf> and
+F<storage.conf> files have been modified, and loads the new configuration
+if needed.
+
 =item B<-m> I<buffer>
 
 Print information about the specified buffer in a format suitable for MRTG.

Modified: doc/pod/news.pod
===================================================================
--- doc/pod/news.pod	2011-08-16 13:50:19 UTC (rev 9340)
+++ doc/pod/news.pod	2011-08-16 13:59:21 UTC (rev 9341)
@@ -131,6 +131,10 @@
 who added support for the syntax of F<incoming.conf>, F<innfeed.conf>,
 F<readers.conf> and F<storage.conf>.
 
+An up to date F<control.ctl> file is provided with this release.  You should
+manually update your F<control.ctl> file with the new information recorded
+about Usenet hierarchies.
+
 =over 2
 
 =item *
@@ -188,6 +192,12 @@
 
 =item *
 
+When the B<-l> flag is given to B<cnfsstat>, the F<cycbuff.conf> and
+F<storage.conf> files are now reloaded if they have been modified since
+the previous output of B<cnfsstat>.
+
+=item *
+
 A single header field line is limited to 998 bytes, per S<RFC 5536>.  B<innd>
 was previously accepting, and also generating Xref: header field lines,
 up to 1022 bytes.  Now, B<nnrpd> (acting as an injecting agent) rejects

Modified: frontends/cnfsstat.in
===================================================================
--- frontends/cnfsstat.in	2011-08-16 13:50:19 UTC (rev 9340)
+++ frontends/cnfsstat.in	2011-08-16 13:59:21 UTC (rev 9341)
@@ -22,6 +22,7 @@
 
 my $conffile = "$INN::Config::pathetc/cycbuff.conf";
 my $storageconf = "$INN::Config::pathetc/storage.conf";
+my $lastconftime = 0;
 
 sub usage {
     print <<"_end_";
@@ -44,8 +45,11 @@
     exit(1);
 }
 
-my (%class, %buff, %stor, @storsort, @buffers);
+my (%class, %buff, %stor, @storsort);
+my (%prevclass, %prevbuff, %prevstor, @prevstorsort);
 
+my @buffers;
+
 my ($oclass, $obuffer);
 my %opt = (c=>\$oclass, m=>\$obuffer);
 Getopt::Long::config('no_ignore_case');
@@ -79,12 +83,12 @@
 my $sleeptime = (defined($opt{'l'}) && $opt{'l'} > 0) ? $opt{'l'} : 600;
 
 unless (read_cycbuffconf()) {
-    print STDERR "Cannot open CycBuff Conffile $conffile ...\n";
+    print STDERR "Invalid $conffile file.\n";
     exit (1);
 }
 
 unless (read_storageconf()) {
-    print STDERR "No valid $storageconf.\n";
+    print STDERR "Invalid $storageconf file.\n";
     exit (1);
 }
 
@@ -95,6 +99,46 @@
 
 START:
 
+# Check whether the configuration files need reloading.
+my $cycbufftime = (stat($conffile))[9] if (-r $conffile);
+my $storagetime = (stat($storageconf))[9] if (-r $storageconf);
+my $maxtime = ($cycbufftime < $storagetime) ? $storagetime : $cycbufftime;
+
+# Set $lastconftime for the first run of the comparison.
+$lastconftime = $maxtime if not $lastconftime;
+
+if ($lastconftime < $maxtime) {
+    my $reloadok = 1;
+
+    $lastconftime = $maxtime;
+
+    # Save the previous configuration, in case reloading it fails.
+    # Direct copies of the arrays and hashes works fine here.
+    %prevclass = %class; undef %class;
+    %prevbuff = %buff; undef %buff;
+    %prevstor = %stor; undef %stor;
+    @prevstorsort = @storsort; undef @storsort;
+
+    unless (read_cycbuffconf()) {
+        print STDERR "Invalid $conffile file.\n";
+        $reloadok = 0;
+    }
+
+    unless (read_storageconf()) {
+        print STDERR "Invalid $storageconf file.\n";
+        $reloadok = 0;
+    }
+
+    # In case reloading configuration files fails, restore the
+    # previous known configuration for this run of cnfsstat.
+    if (!$reloadok) {
+        %class = %prevclass;
+        %buff = %prevbuff;
+        %stor = %prevstor;
+        @storsort = @prevstorsort;
+    }
+}
+
 my $logline;
 my $header_printed = 0;
 my ($gr, $cl, $min, $max);
@@ -216,13 +260,14 @@
 	    @line = split(/:/, $_);
 	    if ($buff{$line[1]}) {
 		print STDERR "Buff $line[1] more than one time in CycBuff Conffile $conffile ...\n";
-		return 1;
+		return 0;
 	    }
 	    $buff{$line[1]} = $line[2];
 	    next;
 	}
 
 	print STDERR "Unknown config line \"$_\" in CycBuff Conffile $conffile ...\n";
+        return 0;
     }
     close $CONFFILE;
     return 1;




More information about the inn-committers mailing list