From 8a9aaff4e8abf8a84dc8c32673c000d75a2b1e06 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sun, 7 Nov 2010 13:28:03 -0800 Subject: [PATCH] Change shell variable resolution order --- Shorewall/Perl/Shorewall/Config.pm | 14 ++++++++------ Shorewall/Perl/getparams | 2 +- Shorewall/releasenotes.txt | 13 +++++++------ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Config.pm b/Shorewall/Perl/Shorewall/Config.pm index 2f953d77f..fc8e3dc10 100644 --- a/Shorewall/Perl/Shorewall/Config.pm +++ b/Shorewall/Perl/Shorewall/Config.pm @@ -1858,16 +1858,19 @@ sub read_a_line(;$) { my $count = 0; # - # Expand Shell Variables using %params + # Expand Shell Variables using %params and %ENV # # $1 $2 $3 - $4 while ( $currentline =~ m( ^(.*?) \$({)? ([a-zA-Z]\w*) (?(2)}) (.*)$ )x ) { + + unless ( exists $params{$3} ) { + $params{$3} = $ENV{$3} if exists $ENV{$3}; + } + my $val = $params{$3}; - - $params{$3} = $ENV{$3} if exists $ENV{$3}; unless ( defined $val ) { - fatal_error "Undefined shell variable (\$$3)" unless exists $params{$3}; + fatal_error "Undefined shell variable (\$$3)" unless exists $params{$3} || exists $ENV{$3}; $val = ''; } @@ -2882,9 +2885,8 @@ sub unsupported_yes_no_warning( $ ) { # Process the params file # sub get_params() { - my $fn = find_file 'params'; + if ( my $fn = find_file 'params' ) { - if ( $fn ) { progress_message2 "Processing $fn ..."; my @params = `$globals{SHAREDIRPL}/getparams $fn`; diff --git a/Shorewall/Perl/getparams b/Shorewall/Perl/getparams index d719f92e9..36d237082 100755 --- a/Shorewall/Perl/getparams +++ b/Shorewall/Perl/getparams @@ -24,7 +24,7 @@ exported=$(env | sed 's/=.*//'); # -# Sigh -- POSIX shells don't support 'typeset' or 'declare' +# Sigh -- POSIX shells don't support 'typeset +x' or 'declare +x' # for v in $exported; do diff --git a/Shorewall/releasenotes.txt b/Shorewall/releasenotes.txt index 88291f89b..dd3b0c6ed 100644 --- a/Shorewall/releasenotes.txt +++ b/Shorewall/releasenotes.txt @@ -30,13 +30,14 @@ VI. PROBLEMS CORRECTED AND NEW FEATURES IN PRIOR RELEASES 1) Previously, /usr/share/shorewall/compiler.pl expected the contents of the params file to be passed in the environment. Now, the - compiler invokes the shell program /usr/share/shorewall/getparams - to process the file and to pass the (variable,value) pairs back to - the compiler. + compiler invokes a small shell program + (/usr/share/shorewall/getparams) to process the file and to pass + the (variable,value) pairs back to the compiler. - In this new implementation, the contents of the environment of the - program that launches /usr/share/shorewall/compiler.pl overrides - the contents of /etc/shorewall/params. + Shell variable expansion uses the value from the params file if the + parameter was set in that file. Otherwise the current environment + is used. If the variable does not appear in either place, an error + message is generated. ---------------------------------------------------------------------------- I V. R E L E A S E 4 . 4 H I G H L I G H T S