Avoid awkward blank lines

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep
2018-01-30 16:32:39 -08:00
parent 09a81ae574
commit a08f0cfe10
6 changed files with 44 additions and 37 deletions

View File

@@ -8509,7 +8509,7 @@ sub save_dynamic_chains() {
); );
if ( have_capability 'IPTABLES_S' ) { if ( have_capability 'IPTABLES_S' ) {
emit <<"EOF"; emithd <<"EOF";
if chain_exists 'UPnP -t nat'; then if chain_exists 'UPnP -t nat'; then
$tool -t nat -S UPnP | tail -n +2 > \${VARDIR}/.UPnP $tool -t nat -S UPnP | tail -n +2 > \${VARDIR}/.UPnP
else else
@@ -8530,6 +8530,7 @@ fi
EOF EOF
if ( $config{MINIUPNPD} ) { if ( $config{MINIUPNPD} ) {
emit << "EOF"; emit << "EOF";
if chain_exists 'MINIUPNPD-POSTROUTING -t nat'; then if chain_exists 'MINIUPNPD-POSTROUTING -t nat'; then
$tool -t nat -S MINIUPNPD-POSTROUTING | tail -n +2 > \${VARDIR}/.MINIUPNPD-POSTROUTING $tool -t nat -S MINIUPNPD-POSTROUTING | tail -n +2 > \${VARDIR}/.MINIUPNPD-POSTROUTING
else else
@@ -8538,7 +8539,7 @@ fi
EOF EOF
} }
} else { } else {
emit <<"EOF"; emithd <<"EOF";
if chain_exists 'UPnP -t nat'; then if chain_exists 'UPnP -t nat'; then
$utility -t nat | grep '^-A UPnP ' > \${VARDIR}/.UPnP $utility -t nat | grep '^-A UPnP ' > \${VARDIR}/.UPnP
else else
@@ -8558,7 +8559,8 @@ else
fi fi
EOF EOF
if ( $config{MINIUPNPD} ) { if ( $config{MINIUPNPD} ) {
emit << "EOF"; emithd << "EOF";
if chain_exists 'MINIUPNPD-POSTROUTING -t nat'; then if chain_exists 'MINIUPNPD-POSTROUTING -t nat'; then
$utility -t nat | grep '^-A MINIUPNPD-POSTROUTING' > \${VARDIR}/.MINIUPNPD-POSTROUTING $utility -t nat | grep '^-A MINIUPNPD-POSTROUTING' > \${VARDIR}/.MINIUPNPD-POSTROUTING
else else
@@ -8572,7 +8574,7 @@ EOF
emit ( 'else' ); emit ( 'else' );
push_indent; push_indent;
emit <<"EOF"; emithd <<"EOF";
rm -f \${VARDIR}/.UPnP rm -f \${VARDIR}/.UPnP
rm -f \${VARDIR}/.forwardUPnP rm -f \${VARDIR}/.forwardUPnP
EOF EOF
@@ -8609,7 +8611,7 @@ sub ensure_ipsets( @ ) {
pop_indent; pop_indent;
emit( qq( fi\n) ); emit( q( fi) );
} }
@@ -8785,7 +8787,6 @@ sub create_load_ipsets() {
' $IPSET flush $set' , ' $IPSET flush $set' ,
' $IPSET destroy $set' , ' $IPSET destroy $set' ,
" done" , " done" ,
'',
); );
} else { } else {
# #
@@ -8797,7 +8798,7 @@ sub create_load_ipsets() {
' fi' ); ' fi' );
}; };
emit( '}' ); emit( "}\n" );
} }
# #
# Now generate load_ipsets() # Now generate load_ipsets()
@@ -8866,20 +8867,17 @@ sub create_load_ipsets() {
ensure_ipsets( @ipsets ); ensure_ipsets( @ipsets );
emit( 'elif [ "$COMMAND" = refresh ]; then' ); ################### Refresh Command ################### emit( 'elif [ "$COMMAND" = refresh ]; then' ); ################### Refresh Command ###################
emit ( '' );
ensure_ipsets( @ipsets ); ensure_ipsets( @ipsets );
emit ( '' );
}; };
emit ( 'fi' , emit ( 'fi' );
'' );
} else { } else {
emit 'true'; emit 'true';
} }
pop_indent; pop_indent;
emit '}'; emit "}\n";
} }
# #
@@ -9052,7 +9050,7 @@ sub create_netfilter_load( $ ) {
"cat \${VARDIR}/.${utility}-input | \$command # Use this nonsensical form to appease SELinux", "cat \${VARDIR}/.${utility}-input | \$command # Use this nonsensical form to appease SELinux",
'if [ $? != 0 ]; then', 'if [ $? != 0 ]; then',
qq( fatal_error "iptables-restore Failed. Input is in \${VARDIR}/.${utility}-input"), qq( fatal_error "iptables-restore Failed. Input is in \${VARDIR}/.${utility}-input"),
"fi\n" 'fi'
); );
pop_indent; pop_indent;

View File

@@ -103,7 +103,7 @@ sub generate_script_1( $ ) {
copy2( $lib, $debug ) if -f $lib; copy2( $lib, $debug ) if -f $lib;
emit <<'EOF'; emithd<<'EOF';
################################################################################ ################################################################################
# Functions to execute the various user exits (extension scripts) # Functions to execute the various user exits (extension scripts)
################################################################################ ################################################################################
@@ -125,7 +125,7 @@ EOF
emit '}'; emit '}';
} }
emit <<'EOF'; emithd <<'EOF';
################################################################################ ################################################################################
# End user exit functions # End user exit functions
################################################################################ ################################################################################
@@ -270,12 +270,11 @@ sub generate_script_2() {
); );
emit( 'chain_exists DOCKER-INGRESS && g_dockeringress=Yes' ); emit( 'chain_exists DOCKER-INGRESS && g_dockeringress=Yes' );
emit( 'chain_exists DOCKER-ISOLATION && g_dockernetwork=Yes' ); emit( 'chain_exists DOCKER-ISOLATION && g_dockernetwork=Yes' );
emit( '' );
} }
pop_indent; pop_indent;
emit "\n}\n"; # End of initialize() emit "}\n"; # End of initialize()
emit( '' , emit( '' ,
'#' , '#' ,
@@ -525,7 +524,7 @@ sub generate_script_3($) {
my $config_dir = $globals{CONFIGDIR}; my $config_dir = $globals{CONFIGDIR};
emit<<"EOF"; emithd <<"EOF";
set_state Started $config_dir set_state Started $config_dir
run_restored_exit run_restored_exit
elif [ \$COMMAND = refresh ]; then elif [ \$COMMAND = refresh ]; then
@@ -572,7 +571,7 @@ EOF
' run_started_exit', ' run_started_exit',
"fi\n" ); "fi\n" );
emit<<'EOF'; emithd<<'EOF';
date > ${VARDIR}/restarted date > ${VARDIR}/restarted
case $COMMAND in case $COMMAND in

View File

@@ -189,6 +189,7 @@ our %EXPORT_TAGS = ( internal => [ qw( create_temp_script
in_hex8 in_hex8
in_hexp in_hexp
emit emit
emithd
emitstd emitstd
emit_unindented emit_unindented
save_progress_message save_progress_message
@@ -1710,6 +1711,15 @@ sub emit {
} }
} }
#
# Used to emit a 'here documents' string without introducing an unwanted blank line at the end
#
sub emithd( $ ) {
my ( $line ) = @_; #make writable
chomp $line;
emit $line;
}
# #
# Version of emit() that writes to standard out unconditionally # Version of emit() that writes to standard out unconditionally
# #

View File

@@ -2646,7 +2646,6 @@ EOF
rm -f ${VARDIR}/proxyarp rm -f ${VARDIR}/proxyarp
fi fi
EOF EOF
} else { } else {
emit <<'EOF'; emit <<'EOF';
@@ -2660,7 +2659,6 @@ EOF
rm -f ${VARDIR}/proxyndp rm -f ${VARDIR}/proxyndp
fi fi
EOF EOF
} }

View File

@@ -876,7 +876,7 @@ sub add_a_provider( $$ ) {
} }
emit( "run_ip route replace default via $gateway src $address dev $physical ${mtu}table $id $realm" ); emit( "run_ip route replace default via $gateway src $address dev $physical ${mtu}table $id $realm" );
emit( qq( echo "\$IP route del default via $gateway src $address dev $physical ${mtu}table $id $realm > /dev/null 2>&1" >> \${VARDIR}/undo_${table}_routing) ); emit( qq(echo "\$IP route del default via $gateway src $address dev $physical ${mtu}table $id $realm > /dev/null 2>&1" >> \${VARDIR}/undo_${table}_routing) );
} }
if ( ! $noautosrc ) { if ( ! $noautosrc ) {
@@ -885,7 +885,8 @@ sub add_a_provider( $$ ) {
emit( "run_ip rule add from $address pref 20000 table $id" , emit( "run_ip rule add from $address pref 20000 table $id" ,
"echo \"\$IP -$family rule del from $address pref 20000> /dev/null 2>&1\" >> \${VARDIR}/undo_${table}_routing" ); "echo \"\$IP -$family rule del from $address pref 20000> /dev/null 2>&1\" >> \${VARDIR}/undo_${table}_routing" );
} else { } else {
emit ( "find_interface_addresses $physical | while read address; do", emit ( '',
"find_interface_addresses $physical | while read address; do",
" qt \$IP -$family rule del from \$address", " qt \$IP -$family rule del from \$address",
" run_ip rule add from \$address pref 20000 table $id", " run_ip rule add from \$address pref 20000 table $id",
" echo \"\$IP -$family rule del from \$address pref 20000 > /dev/null 2>&1\" >> \${VARDIR}/undo_${table}_routing", " echo \"\$IP -$family rule del from \$address pref 20000 > /dev/null 2>&1\" >> \${VARDIR}/undo_${table}_routing",
@@ -1250,7 +1251,7 @@ CEOF
'if [ $COMMAND = disable ]; then', 'if [ $COMMAND = disable ]; then',
" do_persistent_${what}_${table}", " do_persistent_${what}_${table}",
"else", "else",
" echo 1 > \${VARDIR}/${physical}_disabled\n", " echo 1 > \${VARDIR}/${physical}_disabled",
"fi\n", "fi\n",
); );
} }
@@ -1593,7 +1594,8 @@ sub finish_providers() {
} }
if ( $config{USE_DEFAULT_RT} ) { if ( $config{USE_DEFAULT_RT} ) {
emit ( " while qt \$IP -$family route del default table $main; do", emit ( '',
" while qt \$IP -$family route del default table $main; do",
' true', ' true',
' done', ' done',
'' ''
@@ -1739,7 +1741,7 @@ sub process_providers( $ ) {
add_a_provider( $providers{$_}, $tcdevices ) for @providers; add_a_provider( $providers{$_}, $tcdevices ) for @providers;
emit << 'EOF';; emithd << 'EOF';;
# #
# Enable an optional provider # Enable an optional provider
@@ -1785,12 +1787,11 @@ EOF
pop_indent; pop_indent;
pop_indent; pop_indent;
emit << 'EOF';; emithd << 'EOF';;
*) *)
startup_error "$g_interface is not an optional provider or interface" startup_error "$g_interface is not an optional provider or interface"
;; ;;
esac esac
} }
# #
@@ -1894,20 +1895,19 @@ sub setup_providers() {
start_providers; start_providers;
setup_null_routing if $config{NULL_ROUTE_RFC1918}; setup_null_routing, emit '' if $config{NULL_ROUTE_RFC1918};
emit ''; if ( @providers ) {
emit "start_$providers{$_}->{what}_$_" for @providers;
emit "start_$providers{$_}->{what}_$_" for @providers; emit '';
}
emit '';
finish_providers; finish_providers;
emit "\nrun_ip route flush cache"; emit "\nrun_ip route flush cache";
pop_indent; pop_indent;
emit "fi\n"; emit 'fi';
setup_route_marking if @routemarked_interfaces || @load_interfaces; setup_route_marking if @routemarked_interfaces || @load_interfaces;
} else { } else {
@@ -1918,9 +1918,10 @@ sub setup_providers() {
if ( $pseudoproviders ) { if ( $pseudoproviders ) {
emit ''; emit '';
emit "start_$providers{$_}->{what}_$_" for @providers; emit "start_$providers{$_}->{what}_$_" for @providers;
emit '';
} }
emit "\nundo_routing"; emit "undo_routing";
emit "restore_default_route $config{USE_DEFAULT_RT}"; emit "restore_default_route $config{USE_DEFAULT_RT}";
my $standard_routes = @{$providers{main}{routes}} || @{$providers{default}{routes}}; my $standard_routes = @{$providers{main}{routes}} || @{$providers{default}{routes}};
@@ -1945,7 +1946,7 @@ sub setup_providers() {
pop_indent; pop_indent;
emit "fi\n"; emit 'fi';
} }
} }

View File

@@ -96,6 +96,7 @@ sub setup_one_proxy_arp( $$$$$$$ ) {
} }
emit ( "run_ip neigh add proxy $address nud permanent dev $extphy" , emit ( "run_ip neigh add proxy $address nud permanent dev $extphy" ,
'' ,
qq(progress_message " Host $address connected to $interface added to $proto on $extphy"\n) ); qq(progress_message " Host $address connected to $interface added to $proto on $extphy"\n) );
push @proxyarp, "$address $interface $external $haveroute"; push @proxyarp, "$address $interface $external $haveroute";