From e4e61c4193a3900f6d02ae95bdfeba6dd41a01f0 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sat, 22 Dec 2012 11:57:25 -0800 Subject: [PATCH] A more uniform way of handling $max_format Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Config.pm | 12 +++++------- Shorewall/Perl/Shorewall/Raw.pm | 4 ++-- Shorewall/Perl/Shorewall/Tc.pm | 4 ++-- Shorewall/Perl/Shorewall/Zones.pm | 4 ++-- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Config.pm b/Shorewall/Perl/Shorewall/Config.pm index 69eb0ae6a..9ce364943 100644 --- a/Shorewall/Perl/Shorewall/Config.pm +++ b/Shorewall/Perl/Shorewall/Config.pm @@ -1918,7 +1918,7 @@ sub do_open_file( $ ) { $currentfilename = $fname; } -sub open_file( $ ) { +sub open_file( $;$ ) { my $fname = find_file $_[0]; assert( ! defined $currentfile ); @@ -1926,6 +1926,7 @@ sub open_file( $ ) { if ( -f $fname && -s _ ) { $first_entry = 0; $file_format = 1; + $max_format = supplied $_[1] ? $_[1] : 1; do_open_file $fname;; } else { $ifstack = @ifstack; @@ -2463,9 +2464,7 @@ sub push_open( $;$ ) { push @openstack, \@a; @includestack = (); $currentfile = undef; - open_file( $file ); - $max_format = supplied $max ? $max : 1; - + open_file( $file , $max ); } sub pop_open() { @@ -2509,11 +2508,10 @@ sub shorewall { # until we get back to the caller of read_a_line(), we could issue error messages about parsing and # running scripts in the file before we'd even indicated that we are processing it. # -sub first_entry( $;$ ) { - ( $first_entry, my $max ) = @_; +sub first_entry( $ ) { + $first_entry = shift; my $reftype = reftype $first_entry; assert( $reftype eq 'CODE' ) if $reftype; - $max_format = supplied $max ? $max : 1; } sub read_a_line($); diff --git a/Shorewall/Perl/Shorewall/Raw.pm b/Shorewall/Perl/Shorewall/Raw.pm index 372af6c06..f01f8bc41 100644 --- a/Shorewall/Perl/Shorewall/Raw.pm +++ b/Shorewall/Perl/Shorewall/Raw.pm @@ -213,7 +213,7 @@ sub setup_conntrack() { for my $name ( qw/notrack conntrack/ ) { - my $fn = open_file( $name ); + my $fn = open_file( $name, 3 ); if ( $fn ) { @@ -221,7 +221,7 @@ sub setup_conntrack() { my $empty = 1; - first_entry( "$doing $fn..." , 3 ); + first_entry( "$doing $fn..." ); while ( read_a_line( NORMAL_READ ) ) { my ( $source, $dest, $proto, $ports, $sports, $user, $switch ); diff --git a/Shorewall/Perl/Shorewall/Tc.pm b/Shorewall/Perl/Shorewall/Tc.pm index d51bb2829..45ed59e88 100644 --- a/Shorewall/Perl/Shorewall/Tc.pm +++ b/Shorewall/Perl/Shorewall/Tc.pm @@ -2412,9 +2412,9 @@ sub setup_tc() { } ); - if ( my $fn = open_file 'tcrules' ) { + if ( my $fn = open_file( 'tcrules' , 2 ) ) { - first_entry "$doing $fn...", 2; + first_entry "$doing $fn..."; process_tc_rule while read_a_line( NORMAL_READ ); diff --git a/Shorewall/Perl/Shorewall/Zones.pm b/Shorewall/Perl/Shorewall/Zones.pm index 107a0b6d2..6491b54fc 100644 --- a/Shorewall/Perl/Shorewall/Zones.pm +++ b/Shorewall/Perl/Shorewall/Zones.pm @@ -1311,8 +1311,8 @@ sub validate_interfaces_file( $ ) { my @ifaces; my $nextinum = 1; - if ( my $fn = open_file 'interfaces' ) { - first_entry "$doing $fn..." , 2; + if ( my $fn = open_file 'interfaces', 2 ) { + first_entry "$doing $fn..."; push @ifaces, process_interface( $nextinum++, $export ) while read_a_line( NORMAL_READ ); } else { fatal_error q(The 'interfaces' file does not exist or has zero size);