Add file name and line number to diagnostic messages

git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@5746 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb
This commit is contained in:
teastep 2007-03-29 17:36:04 +00:00
parent 3271f183e8
commit 514c0d7d88
4 changed files with 60 additions and 28 deletions

View File

@ -32,8 +32,6 @@ use strict;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT = qw(ALLIPv4 our @EXPORT = qw(ALLIPv4
warning_message
fatal_error
split_line split_line
create_temp_object create_temp_object
finalize_object finalize_object
@ -82,14 +80,6 @@ my $indent = '';
my ( $dir, $file ); # Object's Directory and File my ( $dir, $file ); # Object's Directory and File
my $tempfile; # Temporary File Name my $tempfile; # Temporary File Name
#
# Issue a Warning Message
#
sub warning_message
{
print STDERR " WARNING: @_\n";
}
# #
# Fatal Error # Fatal Error
# #

View File

@ -28,7 +28,10 @@ use warnings;
use Shorewall::Common; use Shorewall::Common;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT = ( qw(find_file our @EXPORT = qw(
warning_message
fatal_error
find_file
open_file open_file
push_open push_open
pop_open pop_open
@ -44,7 +47,7 @@ our @EXPORT = ( qw(find_file
%config %config
%env %env
%capabilities ) ); %capabilities );
our @EXPORT_OK = (); our @EXPORT_OK = ();
our @VERSION = 1.00; our @VERSION = 1.00;
@ -210,6 +213,37 @@ my %capdesc = ( NAT_ENABLED => 'NAT',
COMMENTS => 'Comments', COMMENTS => 'Comments',
ADDRTYPE => 'Address Type Match', ADDRTYPE => 'Address Type Match',
); );
#
# Stash away file references here when we encounter INCLUDE
#
my @openstack;
my $currentfile;
my $currentfilename;
my $currentlinenumber = 0;
#
# Issue a Warning Message
#
sub warning_message
{
if ( $currentfile ) {
print STDERR " WARNING: @_ : $currentfilename#$currentlinenumber\n";
} else {
print STDERR " WARNING: @_\n";
}
}
sub fatal_error {
if ( $currentfile ) {
print STDERR " ERROR: @_ : $currentfilename#$currentlinenumber\n";
} else {
print STDERR " ERROR: @_\n";
}
die "Terminated\n";
}
# #
# Search the CONFIG_PATH for the passed file # Search the CONFIG_PATH for the passed file
# #
@ -281,12 +315,6 @@ sub expand_shell_variables( $ ) {
my $line = $_[0]; $line = $1 . ( $ENV{$2} || '' ) . $3 while $line =~ /^(.*?)\$([a-zA-Z]\w*)(.*)$/; $line; my $line = $_[0]; $line = $1 . ( $ENV{$2} || '' ) . $3 while $line =~ /^(.*?)\$([a-zA-Z]\w*)(.*)$/; $line;
} }
#
# Stash away file references here when we encounter INCLUDE
#
my @openstack;
my $currentfile;
# #
# Open a file, setting $currentfile. # Open a file, setting $currentfile.
# #
@ -297,6 +325,8 @@ sub open_file( $ ) {
if ( -f $fname && -s _ ) { if ( -f $fname && -s _ ) {
open $currentfile, '<', $fname or fatal_error "Unable to open $fname: $!"; open $currentfile, '<', $fname or fatal_error "Unable to open $fname: $!";
$currentlinenumber = 0;
$currentfilename = $fname;
} }
} }
@ -307,7 +337,7 @@ my @pushstack;
sub push_open( $ ) { sub push_open( $ ) {
push @openstack, $currentfile; push @openstack, [ $currentfile, $currentfilename, $currentlinenumber ];
my @a = @openstack; my @a = @openstack;
push @pushstack, \@a; push @pushstack, \@a;
@openstack = (); @openstack = ();
@ -318,7 +348,14 @@ sub push_open( $ ) {
sub pop_open() { sub pop_open() {
@openstack = @{pop @pushstack}; @openstack = @{pop @pushstack};
$currentfile = pop @openstack;
my $arrayref = pop @openstack;
if ( $arrayref ) {
( $currentfile, $currentfilename, $currentlinenumber ) = @$arrayref;
} else {
$currentfile = undef;
}
} }
# #
@ -338,6 +375,7 @@ sub read_a_line {
$line = ''; $line = '';
while ( my $nextline = <$currentfile> ) { while ( my $nextline = <$currentfile> ) {
$currentlinenumber++;
next if $nextline =~ /^\s*#/; next if $nextline =~ /^\s*#/;
next if $nextline =~ /^\s*$/; next if $nextline =~ /^\s*$/;
$nextline =~ s/#.*$//; $nextline =~ s/#.*$//;
@ -357,17 +395,13 @@ sub read_a_line {
fatal_error "Missing file name after 'INCLUDE'" unless @line > 1; fatal_error "Missing file name after 'INCLUDE'" unless @line > 1;
fatal_error "Invalid INCLUDE command: $line" if @line > 2; fatal_error "Invalid INCLUDE command: $line" if @line > 2;
fatal_error "INCLUDEs nested too deeply: $line" if @openstack >= 4;
if ( @openstack == 4 ) {
warning_message "INCLUDEs nested too deeply; $line ignored";
next;
}
my $filename = find_file $line[1]; my $filename = find_file $line[1];
fatal_error "$filename not found" unless ( -f $filename ); fatal_error "INCLUDed file $filename not found" unless ( -f $filename );
push @openstack, $currentfile; push @openstack, [ $currentfile, $currentfilename, $currentlinenumber ];
$currentfile = undef; $currentfile = undef;
@ -379,7 +413,13 @@ sub read_a_line {
close $currentfile; close $currentfile;
$currentfile = pop @openstack; my $arrayref = pop @openstack;
if ( $arrayref ) {
( $currentfile, $currentfilename, $currentlinenumber ) = @$arrayref;
} else {
$currentfile = undef;
}
} }
} }

View File

@ -24,6 +24,7 @@
package Shorewall::IPAddrs; package Shorewall::IPAddrs;
require Exporter; require Exporter;
use Shorewall::Common; use Shorewall::Common;
use Shorewall::Config;
use strict; use strict;

View File

@ -36,6 +36,7 @@
# of all configuration files. Shell variable substitution # of all configuration files. Shell variable substitution
# has been performed on these files. # has been performed on these files.
# TIMESTAMP=Yes -t option specified to /sbin/shorewall # TIMESTAMP=Yes -t option specified to /sbin/shorewall
# FW Firewall zone (for shell-variable expansion).
# #
# This program performs rudimentary shell variable expansion on action and macro files. # This program performs rudimentary shell variable expansion on action and macro files.