INN commit: trunk (3 files)

INN Commit rra at isc.org
Thu Jul 7 11:07:26 UTC 2011


    Date: Thursday, July 7, 2011 @ 04:07:25
  Author: iulius
Revision: 9227

inncheck:  use Getopt::Long

Improve the way inncheck parses the command line arguments.  The last
matching argument is taken into account (consequently, "--noperm --perm
--noperm" is valid, as well as "-q -v").

As -perm is not just the opposite of -noperm, $perms is handled differently.
So 1 is -perm, 0 is -noperm, and -1 is neither.

Use --fix, --perms, etc. in our documentation.  Keep -fix, -perms, etc. for
backward compatibility.

Thanks to Florian Schlichting for this patch.

Modified:
  trunk/doc/pod/checklist.pod
  trunk/doc/pod/inncheck.pod
  trunk/scripts/inncheck.in

-----------------------+
 doc/pod/checklist.pod |    2 
 doc/pod/inncheck.pod  |   46 ++++++++++-----------
 scripts/inncheck.in   |  103 +++++++++++++++---------------------------------
 3 files changed, 56 insertions(+), 95 deletions(-)

Modified: doc/pod/checklist.pod
===================================================================
--- doc/pod/checklist.pod	2011-07-07 08:23:30 UTC (rev 9226)
+++ doc/pod/checklist.pod	2011-07-07 11:07:25 UTC (rev 9227)
@@ -165,7 +165,7 @@
 
 =item *
 
-Run C<< <pathbin in inn.conf>inncheck -a -v -f -pedantic -perm >> and fix anything noted:
+Run C<< <pathbin in inn.conf>inncheck -a -v -f --pedantic --perm >> and fix anything noted:
 B<inncheck> gives a rough check on the appropriateness of the configuration
 files as you go.  (It's the equivalent of C<perl -cw yourfile.pl> for
 Perl scripts.)

Modified: doc/pod/inncheck.pod
===================================================================
--- doc/pod/inncheck.pod	2011-07-07 08:23:30 UTC (rev 9226)
+++ doc/pod/inncheck.pod	2011-07-07 11:07:25 UTC (rev 9227)
@@ -4,7 +4,7 @@
 
 =head1 SYNOPSIS
 
-B<inncheck> [B<-afqv>] [B<-noperm> | B<-perm>] [B<-pedantic>]
+B<inncheck> [B<-afqv>] [B<--noperm> | B<--perm>] [B<--pedantic>]
 [I<file> | I<file>B<=>I<path> ...]
 
 =head1 DESCRIPTION
@@ -44,48 +44,46 @@
 
 =over 4
 
-=item B<-a>
+=item B<-a>, B<--all>
 
 If any I<file> value or I<file>B<=>I<path> pairs (see below) are given,
-then normally only the files they refer to are checked.  Use the B<-a>
-flag to specify that I<all> files should be checked regardless.  In this
-case the form I<file>B<=>I<path> will be the more useful.
+then normally only the files they refer to are checked.  Use the B<-a> (or
+B<--all>) flag to specify that I<all> files should be checked regardless.
+In this case the form I<file>B<=>I<path> will be the more useful.
 
-=item B<-f>
+=item B<-f>, B<--fix>
 
-Use the B<-f> flag to have B<inncheck> print the appropriate
+Use the B<-f> flag (or B<--fix>) to have B<inncheck> print the appropriate
 B<chown>/B<chgrp>/B<chmod> command necessary to fix a problem that it
 reports.  Any other output lines will be prefixed with a hash sign (C<#>)
-to make the output be valid input for a shell.  Note that the B<-perm>
+to make the output be valid input for a shell.  Note that the B<--perm>
 flag must be used as well when using this flag.
 
-=item B<-noperm>
+=item B<--noperm>
 
 To avoid doing any checking of file permissions or ownership, use the
-B<-noperm> option.
+B<--noperm> option.
 
-=item B<-pedantic>
+=item B<--pedantic>
 
-Use the B<-pedantic> option to get reports on things that are not necessarily
+Use the B<--pedantic> option to get reports on things that are not necessarily
 wrong, but may indicate a bad configuration, such as F<inn.conf> missing
 a key.
 
-=item B<-perm>
+=item B<--perm>
 
-B<inncheck> checks all files for permission problems.  If the B<-perm>
+B<inncheck> checks all files for permission problems.  If the B<--perm>
 flag is used, then I<only> the files specified by the I<file> or
 I<file>B<=>I<path> command line arguments will be checked for problems
 other than permission problems.
 
-=item B<-q>
+=item B<-q>, B<--quiet>
 
-Use the B<-q> option to get less output.  When this quiet mode is used,
-the B<-v> flag cannot also be specified.
+Use the B<-q> option (or B<--quiet>) to get less output.
 
-=item B<-v>
+=item B<-v>, B<--verbose>
 
-Use the B<-v> option to get more verbose output.  When this mode is used,
-the B<-q> flag cannot also be specified.
+Use the B<-v> option (or B<--verbose>) to get more verbose output.
 
 =back
 
@@ -99,17 +97,17 @@
 It is recommended to run the following command to be aware of all the
 potential problems B<inncheck> can detect:
 
-    inncheck -a -perm -pedantic
+    inncheck -a --perm --pedantic
 
 To have B<inncheck> check all files for permission problems and to verify
 the syntax of the F<active> and F<incoming.conf> files, do:
 
-    inncheck -perm active incoming.conf
+    inncheck --perm active incoming.conf
 
 To fix the permissions problems noted in the output of the above command,
 modify it as follows:
 
-    inncheck -f -perm | sh
+    inncheck -f --perm | sh
 
 (Note that it is useless to mention the name of the two files since
 permission problems are checked on all files.)
@@ -126,7 +124,7 @@
 
 =head1 BUGS
 
-If the B<-f> and B<-perm> options are used together, along with B<-a> or
+If the B<-f> and B<--perm> options are used together, along with B<-a> or
 some I<file> or I<file>B<=>I<path> arguments that refer to a file with
 a syntax problem, then the output will no longer be valid input for a shell.
 

Modified: scripts/inncheck.in
===================================================================
--- scripts/inncheck.in	2011-07-07 08:23:30 UTC (rev 9226)
+++ scripts/inncheck.in	2011-07-07 11:07:25 UTC (rev 9227)
@@ -6,6 +6,7 @@
 ##  by Brendan Kehoe <brendan at cygnus.com> and Rich $alz.
 
 use strict;
+use Getopt::Long;
 
 my $ST_MODE = 2;
 my $ST_UID  = 4;
@@ -88,7 +89,9 @@
 my $exitval = 0;
 
 ##  Command line arguments.
-my ($all, $verbose, $pedantic, $fix, $perms, $noperms, $pfx, @todo);
+##  Note that $perms can be 1 (if --perm), 0 (if --noperm)
+##  and -1 (the default, when no flag is specified).
+my ($all, $verbose, $pedantic, $fix, $perms, $pfx, @todo) = (0, 0, 0, 0, -1, '', ());
 
 my $program = $0;
 $program =~ s at .*/@@;
@@ -1167,9 +1170,9 @@
     print "Usage error: @_.\n";
     print
 "Usage:
-	$program [-afv] [-noperm|perm] [-pedantic] [file | file=value...]
+	$program [-afqv] [--noperm|perm] [--pedantic] [file | file=value...]
 File to check may be followed by \"=path\" to use the specified path.  All
-files are checked if -a is used or if -perm is not used.  Files that may
+files are checked if -a is used or if --perm is not used.  Files that may
 be checked are:\n";
     foreach ( sort(keys %checklist) ) {
 	printf "     %-20s", $_;
@@ -1184,77 +1187,37 @@
 }
 
 
-sub
-parse_flags
-{
-    $all = 0;
-    $fix = 0;
-    $perms = 0;
-    $noperms = 0;
-    $verbose = 0;
-    @todo = ();
+Getopt::Long::Configure('bundling_override');
+GetOptions(
+    'all|a'     => \$all,
+    'verbose|v' => \$verbose,
+    'quiet|q'   => sub { $verbose = -1 },
+    'pedantic'  => \$pedantic,
+    'fix|f'     => \$fix,
+    'perm!'     => \$perms,
+) or Usage("Unknown option");
 
-    arg: foreach ( @ARGV ) {
-	if ( /-a/ ) {
-	    $all++;
-	    next arg;
-	}
-	if ( /^-v/ ) {
-            &Usage("Can't use both `-q' and `-v'")
-                if $verbose != 0;
-	    $verbose++;
-	    next arg;
-	}
-	if ( /^-q/ ) {
-            &Usage("Can't use both `-q' and `-v'")
-                if $verbose != 0;
-	    $verbose--;
-	    next arg;
-	}
-	if ( /^-ped/ ) {
-	    $pedantic++;
-	    next arg;
-	}
-	if ( /^-f/ ) {
-	    $fix++;
-	    next arg;
-	}
-	if ( /^-per/ ) {
-	    $perms++;
-	    next arg;
-	}
-	if ( /^-noperm/ ) {
-	    $noperms++;
-	    next arg;
-	}
-	if ( /^-/ ) {
-	    &Usage("Unknown flag `$_'");
-	}
-	if ( my ($k, $v) = /(.*)=(.*)/ ) {
-	    &Usage("Can't check `$k'")
-		if !defined $checklist{$k};
-	    push(@todo, $k);
-	    $paths{$k} = $v;
-	    next arg;
-	}
-	&Usage("Can't check `$_'")
-	    if !defined $checklist{$_};
-	push(@todo, $_);
+arg: foreach ( @ARGV ) {
+    if ( my ($k, $v) = /(.*)=(.*)/ ) {
+        Usage("Can't check `$k'")
+            if !defined $checklist{$k};
+        push(@todo, $k);
+        $paths{$k} = $v;
+        next arg;
     }
 
-    &Usage("Can't use `-fix' without `-perm'")
-	if $fix && !$perms;
-    &Usage("Can't use `-noperm' with `-perm'")
-	if $noperms && $perms;
-    $pfx = $fix ? '# ' : '';
-
-    @todo = grep(defined $checklist{$_}, sort(keys %paths))
-	if $all || (scalar(@todo) == 0 && ! $perms);
-    return;
+    Usage("Can't check `$_'")
+        if !defined $checklist{$_};
+    push(@todo, $_);
 }
 
+&Usage("Can't use `--fix' without `--perm'")
+    if $fix && $perms < 1;
+$pfx = $fix ? '# ' : '';
 
-&parse_flags();
+ at todo = grep(defined $checklist{$_}, sort(keys %paths))
+    if $all || (scalar(@todo) == 0 && $perms < 1);
+
 action: foreach my $workfile ( @todo ) {
     $file = $paths{$workfile};
     if ( ! -f $file ) {
@@ -1268,12 +1231,12 @@
 	next action;
     }
     &checkperm($file, $modes{$workfile})
-	if $noperms == 0 && !$perms && defined $modes{$workfile};
+	if $perms == -1 && defined $modes{$workfile};
     $line = 0;
     $checklist{$workfile}();
     close($IN);
 }
 
 &check_all_perms()
-    if $perms;
+    if $perms == 1;
 exit($exitval);




More information about the inn-committers mailing list