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
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

View File

@ -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:

View File

@ -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

View File

@ -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.
#

View File

@ -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
#

View File

@ -31,6 +31,7 @@
# --verbosity=<number> # Set VERBOSITY
# --directory=<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 <none>
#
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=<directory> ] [ --verbose={0-2} ] [ --timestamp ] [ <filename> ]\n";
print STDERR "usage: compiler.pl [ --export ] [ --directory=<directory> ] [ --verbose={0-2} ] [ --timestamp ] [ -- debuging ] [ <filename> ]\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;