Report the call site when issuing messages from an action.

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2017-03-17 17:08:19 -07:00
parent 6b84727886
commit bdcf93f92c
No known key found for this signature in database
GPG Key ID: 96E6B3F2423A4D10

View File

@ -748,7 +748,7 @@ sub initialize( $;$$) {
TC_SCRIPT => '', TC_SCRIPT => '',
EXPORT => 0, EXPORT => 0,
KLUDGEFREE => '', KLUDGEFREE => '',
VERSION => "5.1.3", VERSION => "5.1.4-Beta1",
CAPVERSION => 50100 , CAPVERSION => 50100 ,
BLACKLIST_LOG_TAG => '', BLACKLIST_LOG_TAG => '',
RELATED_LOG_TAG => '', RELATED_LOG_TAG => '',
@ -1092,7 +1092,7 @@ sub initialize( $;$$) {
%compiler_params = (); %compiler_params = ();
%actparams = ( 0 => 0, loglevel => '', logtag => '', chain => '', disposition => '', caller => '' ); %actparams = ( 0 => 0, loglevel => '', logtag => '', chain => '', disposition => '', caller => '', callfile => '', callline => '' );
$parmsmodified = 0; $parmsmodified = 0;
$usedcaller = 0; $usedcaller = 0;
%ipsets = (); %ipsets = ();
@ -1218,7 +1218,7 @@ sub compiletime() {
sub currentlineinfo() { sub currentlineinfo() {
my $linenumber = $currentlinenumber || 1; my $linenumber = $currentlinenumber || 1;
if ( $currentfile ) { if ( $currentfilename ) {
my $lineinfo = " $currentfilename "; my $lineinfo = " $currentfilename ";
if ( $linenumber eq 'EOF' ) { if ( $linenumber eq 'EOF' ) {
@ -2834,6 +2834,7 @@ sub evaluate_expression( $$$$ ) {
$val; $val;
} }
sub pop_open();
# #
# Set callback # Set callback
# #
@ -2854,7 +2855,8 @@ sub process_compiler_directive( $$$$ ) {
print "CD===> $line\n" if $debug; print "CD===> $line\n" if $debug;
directive_error( "Invalid compiler directive ($line)" , $filename, $linenumber ) unless $line =~ /^\s*\?(IF\s+|ELSE|ELSIF\s+|ENDIF|SET\s+|RESET\s+|FORMAT\s+|COMMENT\s*|ERROR\s+|WARNING\s+|INFO\s+|WARNING!\s+|INFO!\s+|REQUIRE\s+)(.*)$/i; directive_error( "Invalid compiler directive ($line)" , $filename, $linenumber )
unless $line =~ /^\s*\?(IF\s+|ELSE|ELSIF\s+|ENDIF|SET\s+|RESET\s+|FORMAT\s+|COMMENT\s*|ERROR\s+|WARNING\s+|INFO\s+|WARNING!\s+|INFO!\s+|REQUIRE\s+)(.*)$/i;
my ($keyword, $expression) = ( uc $1, $2 ); my ($keyword, $expression) = ( uc $1, $2 );
@ -2995,68 +2997,165 @@ sub process_compiler_directive( $$$$ ) {
ERROR => sub() { ERROR => sub() {
unless ( $omitting ) { unless ( $omitting ) {
directive_error( evaluate_expression( $expression , if ( $actparams{0} ) {
$filename , close $currentfile;
$linenumber , #
1 ) , # Avoid 'missing ?ENDIF' error in pop_open'
$filename , #
$linenumber ) unless $omitting; @ifstack = ();
#
# Avoid double-reporting the action call site
#
pop_open;
directive_error( evaluate_expression( $expression ,
$filename ,
$linenumber ,
1 ) ,
$actparams{callfile} ,
$actparams{callline} );
} else {
directive_error( evaluate_expression( $expression ,
$filename ,
$linenumber ,
1 ) ,
$filename ,
$linenumber ) unless $omitting;
}
} }
} , } ,
WARNING => sub() { WARNING => sub() {
unless ( $omitting ) { unless ( $omitting ) {
directive_warning( $config{VERBOSE_MESSAGES} , if ( $actparams{0} ) {
evaluate_expression( $expression , #
$filename , # Avoid double-reporting the action call site
$linenumber , #
1 ), my $saveopens = pop @openstack;
$filename ,
$linenumber ) unless $omitting; directive_warning( $config{VERBOSE_MESSAGES} ,
evaluate_expression( $expression ,
$filename ,
$linenumber ,
1 ),
$actparams{callfile} ,
$actparams{callline} );
push @openstack, $saveopens;
} else {
directive_warning( $config{VERBOSE_MESSAGES} ,
evaluate_expression( $expression ,
$filename ,
$linenumber ,
1 ),
$filename ,
$linenumber );
}
} }
} , } ,
INFO => sub() { INFO => sub() {
unless ( $omitting ) { unless ( $omitting ) {
directive_info( $config{VERBOSE_MESSAGES} , if ( $actparams{0} ) {
evaluate_expression( $expression , #
$filename , # Avoid double-reporting the action call site
$linenumber , #
1 ), my $saveopens = pop @openstack;
$filename ,
$linenumber ) unless $omitting; directive_info( $config{VERBOSE_MESSAGES} ,
evaluate_expression( $expression ,
$filename ,
$linenumber ,
1 ),
$actparams{callfile} ,
$actparams{callline} );
push @openstack, $saveopens;
} else {
directive_info( $config{VERBOSE_MESSAGES} ,
evaluate_expression( $expression ,
$filename ,
$linenumber ,
1 ),
$filename ,
$linenumber );
}
} }
} , } ,
'WARNING!' => sub() { 'WARNING!' => sub() {
unless ( $omitting ) { unless ( $omitting ) {
directive_warning( ! $config{VERBOSE_MESSAGES} , if ( $actparams{0} ) {
evaluate_expression( $expression , #
$filename , # Avoid double-reporting the action call site
$linenumber , #
1 ), my $saveopens = pop @openstack;
$filename ,
$linenumber ) unless $omitting; directive_warning( ! $config{VERBOSE_MESSAGES} ,
evaluate_expression( $expression ,
$filename ,
$linenumber ,
1 ),
$actparams{callfile} ,
$actparams{callline} );
push @openstack, $saveopens;
} else {
directive_warning( ! $config{VERBOSE_MESSAGES} ,
evaluate_expression( $expression ,
$filename ,
$linenumber ,
1 ),
$filename ,
$linenumber );
}
} }
} , } ,
'INFO!' => sub() { 'INFO!' => sub() {
unless ( $omitting ) { unless ( $omitting ) {
directive_info( ! $config{VERBOSE_MESSAGES} , if ( $actparams{0} ) {
evaluate_expression( $expression , #
$filename , # Avoid double-reporting the action call site
$linenumber , #
1 ), my $saveopens = pop @openstack;
$filename ,
$linenumber ) unless $omitting; directive_info( ! $config{VERBOSE_MESSAGES} ,
evaluate_expression( $expression ,
$filename ,
$linenumber ,
1 ),
$actparams{callfile} ,
$actparams{callline} );
push @openstack, $saveopens;
} else {
directive_info( ! $config{VERBOSE_MESSAGES} ,
evaluate_expression( $expression ,
$filename ,
$linenumber ,
1 ),
$filename ,
$linenumber );
}
} }
} , } ,
REQUIRE => sub() { REQUIRE => sub() {
unless ( $omitting ) { unless ( $omitting ) {
fatal_error "?REQUIRE may only be used within action files" unless $actparams{0}; fatal_error "?REQUIRE may only be used within action files" unless $actparams{0};
fatal_error "Unknown capability ($expression)" unless $capdesc{$expression}; fatal_error "Unknown capability ($expression)" unless ( my $capdesc = $capdesc{$expression} );
require_capability( $expression, "The $actparams{action} action", 's' ); unless ( have_capability( $expression ) ) {
close $currentfile;
#
# Avoid 'missing ?ENDIF' error in pop_open'
#
@ifstack = ();
#
# Avoid double-reporting the action call site
#
pop_open;
directive_error( "The $actparams{action} action requires the $capdesc capability",
$actparams{callfile} ,
$actparams{callline} );
}
} }
} , } ,
@ -3558,6 +3657,8 @@ sub push_action_params( $$$$$$ ) {
$actparams{loglevel} = $loglevel; $actparams{loglevel} = $loglevel;
$actparams{logtag} = $logtag; $actparams{logtag} = $logtag;
$actparams{caller} = $caller; $actparams{caller} = $caller;
$actparams{callfile} = $currentfilename;
$actparams{callline} = $currentlinenumber;
$actparams{disposition} = '' if $chainref->{action}; $actparams{disposition} = '' if $chainref->{action};
# #
# The Shorewall variable '@chain' has non-word characters other than hyphen removed # The Shorewall variable '@chain' has non-word characters other than hyphen removed