From e21398c1ebf496eedb4e71adee9abbd028b20db9 Mon Sep 17 00:00:00 2001 From: teastep Date: Sat, 23 Jun 2007 21:12:48 +0000 Subject: [PATCH] First step at adding supportability features to Shorewall-perl git-svn-id: https://shorewall.svn.sourceforge.net/svnroot/shorewall/trunk@6657 fbd18981-670d-0410-9b5c-8dc0c1a9a2bb --- Shorewall-common/changelog.txt | 2 ++ Shorewall-common/releasenotes.txt | 8 +++++++- Shorewall-common/shorewall | 1 + Shorewall-perl/Shorewall/Compiler.pm | 6 ++++-- Shorewall-perl/Shorewall/Config.pm | 21 +++++++++++++++++++-- Shorewall-perl/compiler.pl | 10 ++++++++-- 6 files changed, 41 insertions(+), 7 deletions(-) diff --git a/Shorewall-common/changelog.txt b/Shorewall-common/changelog.txt index 0a38567a1..9a6056511 100644 --- a/Shorewall-common/changelog.txt +++ b/Shorewall-common/changelog.txt @@ -10,6 +10,8 @@ Changes in 4.0.0 Beta 6 5) Implement VALIDATE_PORTS +6) First step to adding compiler debugging facility. + Changes in 4.0.0 Beta 5 1) Fix undefined function call when both an input interface and an diff --git a/Shorewall-common/releasenotes.txt b/Shorewall-common/releasenotes.txt index e76732362..c83aca643 100644 --- a/Shorewall-common/releasenotes.txt +++ b/Shorewall-common/releasenotes.txt @@ -658,13 +658,19 @@ Migration Considerations: If given, each progress message issued by the compiler and by the compiled program will be timestamped. + --debugging + + If given, when a warning or error message is issued, it is + supplimented with a stack trace. Requires the Carp Perl + module. + Example (compiles the configuration in the current directory generating a script named 'firewall' and using VERBOSITY 2). /usr/share/shorewall-perl/compiler.pl -v 2 -d . firewall - Note: For compatibility with Shorewall 3.4.2 and later 3.4 + Note: For compatibility with the Shorewall 3.4.2 and 3.4.3 releases, options not passed on the run-line get their values from environmental variables: diff --git a/Shorewall-common/shorewall b/Shorewall-common/shorewall index a20d8f7ba..9c94be5ad 100755 --- a/Shorewall-common/shorewall +++ b/Shorewall-common/shorewall @@ -343,6 +343,7 @@ compiler() { [ -n "$EXPORT" ] && options="$options --export "; [ -n "$SHOREWALL_DIR" ] && options="$options --directory $SHOREWALL_DIR "; [ -n "$TIMESTAMP" ] && options="$options --timestamp" ; + [ -n "$debugging" ] && options="$options --debug" ; [ -x $pc ] || startup_error "SHOREWALL_COMPILER=perl requires the shorewall-perl package which is not installed" # # Run the appropriate params file diff --git a/Shorewall-perl/Shorewall/Compiler.pm b/Shorewall-perl/Shorewall/Compiler.pm index e995b34b0..419bebde7 100644 --- a/Shorewall-perl/Shorewall/Compiler.pm +++ b/Shorewall-perl/Shorewall/Compiler.pm @@ -43,7 +43,7 @@ use Shorewall::Proc; use Shorewall::Proxyarp; our @ISA = qw(Exporter); -our @EXPORT = qw( compiler EXPORT TIMESTAMP ); +our @EXPORT = qw( compiler EXPORT TIMESTAMP DEBUG ); our @EXPORT_OK = qw( $export ); our $VERSION = 1.00; @@ -52,7 +52,8 @@ our $export; our $reused = 0; use constant { EXPORT => 0x01 , - TIMESTAMP => 0x02 }; + TIMESTAMP => 0x02 , + DEBUG => 0x04 }; # # Reinitilize the package-globals in the other modules @@ -690,6 +691,7 @@ sub compiler( $$$$ ) { set_verbose( $verbosity ) unless $verbosity eq ''; $export = 1 if $options & EXPORT; set_timestamp( 1 ) if $options & TIMESTAMP; + set_debug( 1 ) if $options & DEBUG; # # Get shorewall.conf and capabilities. # diff --git a/Shorewall-perl/Shorewall/Config.pm b/Shorewall-perl/Shorewall/Config.pm index 9ebccc7d2..d492053c6 100644 --- a/Shorewall-perl/Shorewall/Config.pm +++ b/Shorewall-perl/Shorewall/Config.pm @@ -37,6 +37,7 @@ our @EXPORT = qw( warning_message fatal_error set_shorewall_dir + set_debug find_file split_line split_line1 @@ -107,6 +108,8 @@ our $currentlinenumber; # Line number our $shorewall_dir; #Shorewall Directory +our $debug; + # # Initialize globals -- we take this novel approach to globals initialization to allow # the compiler to run multiple times in the same process. The @@ -306,6 +309,8 @@ sub initialize() { $currentlinenumber = 0; # Line number $shorewall_dir = ''; #Shorewall Directory + + $debug = 0; } INIT { @@ -319,7 +324,11 @@ sub warning_message { my $lineinfo = $currentfile ? " : $currentfilename (line $currentlinenumber)" : ''; - print STDERR " WARNING: @_$lineinfo\n"; + if ( $debug ) { + print STDERR Carp::longmess( "WARNING: @_$lineinfo" ); + } else { + print STDERR " WARNING: @_$lineinfo\n"; + } } # @@ -327,7 +336,7 @@ sub warning_message # sub fatal_error { my $lineinfo = $currentfile ? " : $currentfilename (line $currentlinenumber)" : ''; - + Carp::confess "ERROR: @_$lineinfo" if $debug; die " ERROR: @_$lineinfo\n"; } @@ -339,6 +348,14 @@ sub set_shorewall_dir( $ ) { $shorewall_dir = shift; } +# +# Set $debug +# +sub set_debug( $ ) { + use Carp; + $debug = shift; +} + # # Search the CONFIG_PATH for the passed file # diff --git a/Shorewall-perl/compiler.pl b/Shorewall-perl/compiler.pl index cf74ce11d..c5c11cd92 100755 --- a/Shorewall-perl/compiler.pl +++ b/Shorewall-perl/compiler.pl @@ -31,6 +31,7 @@ # --verbosity= # Set VERBOSITY # --directory= # Directory where configuration resides (default is /etc/shorewall) # --timestamp # Timestamp all progress messages +# --debugging # Print stack trace on warnings and fatal error. # # Default values for compiler options are given in environmental variables as follows: # @@ -40,6 +41,7 @@ # --export EXPORT # --directory SHOREWALL_DIR # --timestamp TIMESTAMP +# --debugging # use strict; use lib '/usr/share/shorewall-perl'; @@ -47,7 +49,7 @@ use Shorewall::Compiler; use Getopt::Long; sub usage() { - print STDERR "usage: compiler.pl [ --export ] [ --directory= ] [ --verbose={0-2} ] [ --timestamp ] [ ]\n"; + print STDERR "usage: compiler.pl [ --export ] [ --directory= ] [ --verbose={0-2} ] [ --timestamp ] [ -- debuging ] [ ]\n"; exit 1; } @@ -58,6 +60,7 @@ my $export = $ENV{EXPORT} || 0; my $shorewall_dir = $ENV{SHOREWALL_DIR} || ''; my $verbose = $ENV{VERBOSE} || 0; my $timestamp = $ENV{TIMESTAMP} || ''; +my $debug = 0; Getopt::Long::Configure ('bundling'); @@ -68,7 +71,9 @@ my $result = GetOptions('export' => \$export, 'verbose=i' => \$verbose, 'v=i' => \$verbose, 'timestamp' => \$timestamp, - 't' => \$timestamp ); + 't' => \$timestamp, + 'debugging' => \$debug + ); usage unless $result && @ARGV < 2; @@ -76,5 +81,6 @@ my $options = 0; $options |= EXPORT if $export; $options |= TIMESTAMP if $timestamp; +$options |= DEBUG if $debug; compiler $ARGV[0], $shorewall_dir, $verbose, $options;