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
This commit is contained in:
teastep 2007-06-23 21:12:48 +00:00
parent ed873df7bc
commit e21398c1eb
6 changed files with 41 additions and 7 deletions

View File

@ -10,6 +10,8 @@ Changes in 4.0.0 Beta 6
5) Implement VALIDATE_PORTS 5) Implement VALIDATE_PORTS
6) First step to adding compiler debugging facility.
Changes in 4.0.0 Beta 5 Changes in 4.0.0 Beta 5
1) Fix undefined function call when both an input interface and an 1) Fix undefined function call when both an input interface and an

View File

@ -658,13 +658,19 @@ Migration Considerations:
If given, each progress message issued by the compiler and by If given, each progress message issued by the compiler and by
the compiled program will be timestamped. 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 Example (compiles the configuration in the current directory
generating a script named 'firewall' and using VERBOSITY generating a script named 'firewall' and using VERBOSITY
2). 2).
/usr/share/shorewall-perl/compiler.pl -v 2 -d . firewall /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 releases, options not passed on the run-line get their values from
environmental variables: environmental variables:

View File

@ -343,6 +343,7 @@ compiler() {
[ -n "$EXPORT" ] && options="$options --export "; [ -n "$EXPORT" ] && options="$options --export ";
[ -n "$SHOREWALL_DIR" ] && options="$options --directory $SHOREWALL_DIR "; [ -n "$SHOREWALL_DIR" ] && options="$options --directory $SHOREWALL_DIR ";
[ -n "$TIMESTAMP" ] && options="$options --timestamp" ; [ -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" [ -x $pc ] || startup_error "SHOREWALL_COMPILER=perl requires the shorewall-perl package which is not installed"
# #
# Run the appropriate params file # Run the appropriate params file

View File

@ -43,7 +43,7 @@ use Shorewall::Proc;
use Shorewall::Proxyarp; use Shorewall::Proxyarp;
our @ISA = qw(Exporter); our @ISA = qw(Exporter);
our @EXPORT = qw( compiler EXPORT TIMESTAMP ); our @EXPORT = qw( compiler EXPORT TIMESTAMP DEBUG );
our @EXPORT_OK = qw( $export ); our @EXPORT_OK = qw( $export );
our $VERSION = 1.00; our $VERSION = 1.00;
@ -52,7 +52,8 @@ our $export;
our $reused = 0; our $reused = 0;
use constant { EXPORT => 0x01 , use constant { EXPORT => 0x01 ,
TIMESTAMP => 0x02 }; TIMESTAMP => 0x02 ,
DEBUG => 0x04 };
# #
# Reinitilize the package-globals in the other modules # Reinitilize the package-globals in the other modules
@ -690,6 +691,7 @@ sub compiler( $$$$ ) {
set_verbose( $verbosity ) unless $verbosity eq ''; set_verbose( $verbosity ) unless $verbosity eq '';
$export = 1 if $options & EXPORT; $export = 1 if $options & EXPORT;
set_timestamp( 1 ) if $options & TIMESTAMP; set_timestamp( 1 ) if $options & TIMESTAMP;
set_debug( 1 ) if $options & DEBUG;
# #
# Get shorewall.conf and capabilities. # Get shorewall.conf and capabilities.
# #

View File

@ -37,6 +37,7 @@ our @EXPORT = qw(
warning_message warning_message
fatal_error fatal_error
set_shorewall_dir set_shorewall_dir
set_debug
find_file find_file
split_line split_line
split_line1 split_line1
@ -107,6 +108,8 @@ our $currentlinenumber; # Line number
our $shorewall_dir; #Shorewall Directory our $shorewall_dir; #Shorewall Directory
our $debug;
# #
# Initialize globals -- we take this novel approach to globals initialization to allow # Initialize globals -- we take this novel approach to globals initialization to allow
# the compiler to run multiple times in the same process. The # the compiler to run multiple times in the same process. The
@ -306,6 +309,8 @@ sub initialize() {
$currentlinenumber = 0; # Line number $currentlinenumber = 0; # Line number
$shorewall_dir = ''; #Shorewall Directory $shorewall_dir = ''; #Shorewall Directory
$debug = 0;
} }
INIT { INIT {
@ -319,15 +324,19 @@ sub warning_message
{ {
my $lineinfo = $currentfile ? " : $currentfilename (line $currentlinenumber)" : ''; my $lineinfo = $currentfile ? " : $currentfilename (line $currentlinenumber)" : '';
if ( $debug ) {
print STDERR Carp::longmess( "WARNING: @_$lineinfo" );
} else {
print STDERR " WARNING: @_$lineinfo\n"; print STDERR " WARNING: @_$lineinfo\n";
} }
}
# #
# Issue fatal error message and die # Issue fatal error message and die
# #
sub fatal_error { sub fatal_error {
my $lineinfo = $currentfile ? " : $currentfilename (line $currentlinenumber)" : ''; my $lineinfo = $currentfile ? " : $currentfilename (line $currentlinenumber)" : '';
Carp::confess "ERROR: @_$lineinfo" if $debug;
die " ERROR: @_$lineinfo\n"; die " ERROR: @_$lineinfo\n";
} }
@ -339,6 +348,14 @@ sub set_shorewall_dir( $ ) {
$shorewall_dir = shift; $shorewall_dir = shift;
} }
#
# Set $debug
#
sub set_debug( $ ) {
use Carp;
$debug = shift;
}
# #
# Search the CONFIG_PATH for the passed file # Search the CONFIG_PATH for the passed file
# #

View File

@ -31,6 +31,7 @@
# --verbosity=<number> # Set VERBOSITY # --verbosity=<number> # Set VERBOSITY
# --directory=<directory> # Directory where configuration resides (default is /etc/shorewall) # --directory=<directory> # Directory where configuration resides (default is /etc/shorewall)
# --timestamp # Timestamp all progress messages # --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: # Default values for compiler options are given in environmental variables as follows:
# #
@ -40,6 +41,7 @@
# --export EXPORT # --export EXPORT
# --directory SHOREWALL_DIR # --directory SHOREWALL_DIR
# --timestamp TIMESTAMP # --timestamp TIMESTAMP
# --debugging <none>
# #
use strict; use strict;
use lib '/usr/share/shorewall-perl'; use lib '/usr/share/shorewall-perl';
@ -47,7 +49,7 @@ use Shorewall::Compiler;
use Getopt::Long; use Getopt::Long;
sub usage() { sub usage() {
print STDERR "usage: compiler.pl [ --export ] [ --directory=<directory> ] [ --verbose={0-2} ] [ --timestamp ] [ <filename> ]\n"; print STDERR "usage: compiler.pl [ --export ] [ --directory=<directory> ] [ --verbose={0-2} ] [ --timestamp ] [ -- debuging ] [ <filename> ]\n";
exit 1; exit 1;
} }
@ -58,6 +60,7 @@ my $export = $ENV{EXPORT} || 0;
my $shorewall_dir = $ENV{SHOREWALL_DIR} || ''; my $shorewall_dir = $ENV{SHOREWALL_DIR} || '';
my $verbose = $ENV{VERBOSE} || 0; my $verbose = $ENV{VERBOSE} || 0;
my $timestamp = $ENV{TIMESTAMP} || ''; my $timestamp = $ENV{TIMESTAMP} || '';
my $debug = 0;
Getopt::Long::Configure ('bundling'); Getopt::Long::Configure ('bundling');
@ -68,7 +71,9 @@ my $result = GetOptions('export' => \$export,
'verbose=i' => \$verbose, 'verbose=i' => \$verbose,
'v=i' => \$verbose, 'v=i' => \$verbose,
'timestamp' => \$timestamp, 'timestamp' => \$timestamp,
't' => \$timestamp ); 't' => \$timestamp,
'debugging' => \$debug
);
usage unless $result && @ARGV < 2; usage unless $result && @ARGV < 2;
@ -76,5 +81,6 @@ my $options = 0;
$options |= EXPORT if $export; $options |= EXPORT if $export;
$options |= TIMESTAMP if $timestamp; $options |= TIMESTAMP if $timestamp;
$options |= DEBUG if $debug;
compiler $ARGV[0], $shorewall_dir, $verbose, $options; compiler $ARGV[0], $shorewall_dir, $verbose, $options;