From d3ef88e2e95a28f224c0b5d4b441339313ed2a66 Mon Sep 17 00:00:00 2001 From: Olivier Blin Date: Fri, 2 Dec 2011 23:07:16 +0000 Subject: do not write end line twice in shorewall files if there is no "LAST LINE" marker --- lib/network/shorewall.pm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/network/shorewall.pm b/lib/network/shorewall.pm index 46bafed..f07edf3 100644 --- a/lib/network/shorewall.pm +++ b/lib/network/shorewall.pm @@ -22,8 +22,10 @@ sub set_config_file { my $done; substInFile { - if (!$done && (/^#LAST LINE/ || eof)) { - $_ = join('', map { join("\t", @$_) . "\n" } @l) . $_; + my $last_line = /^#LAST LINE/ && $_; + if (!$done && ($last_line || eof)) { + $_ = join('', map { join("\t", @$_) . "\n" } @l); + $_ .= $last_line if $last_line; $done = 1; } else { $_ = '' if /^[^#]/; @@ -40,9 +42,11 @@ sub set_in_file { my ($file, $enabled, @list) = @_; my $done; substInFile { + my $last_line = /^#LAST LINE/ && $_; foreach my $l (@list) { s|^$l\n|| } - if (!$done && $enabled && (/^#LAST LINE/ || eof)) { - $_ = join('', map { "$_\n" } @list) . $_; + if (!$done && $enabled && ($last_line || eof)) { + $_ = join('', map { "$_\n" } @list); + $_ .= $last_line if $last_line; $done = 1; } } "$::prefix/etc/shorewall/$file"; -- cgit v1.2.1