From 2d083c4aba26b08c68f812119d49e70328d9ef8b Mon Sep 17 00:00:00 2001 From: Gaurav Sinha Date: Thu, 7 Jun 2012 23:19:36 -0700 Subject: re-factored deletion code, disabling module scripts fixed --- lib/Vyatta/Conntrack/ConntrackUtil.pm | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'lib/Vyatta') diff --git a/lib/Vyatta/Conntrack/ConntrackUtil.pm b/lib/Vyatta/Conntrack/ConntrackUtil.pm index bdc4961..0ded3ef 100644 --- a/lib/Vyatta/Conntrack/ConntrackUtil.pm +++ b/lib/Vyatta/Conntrack/ConntrackUtil.pm @@ -41,7 +41,7 @@ sub process_protocols { close $proto; return \%proto_hash; } -our @EXPORT = qw(check_for_conntrack_hooks, process_protocols, check_and_add_helpers); +our @EXPORT = qw(check_for_conntrack_hooks, process_protocols, check_and_add_helpers, run_cmd); #function to find if connection tracking is enabled. #looks in the iptables to see if any of the features introduced @@ -83,4 +83,36 @@ sub check_and_add_helpers { check_ct_helper_rules(); } } + +sub log_msg { + my $message = shift; + + print "DEBUG: $message\n" if $debug_flag; + syslog(LOG_DEBUG, "%s", $message) if $syslog_flag; +} +# Run command and capture output +# run_cmd("$iptables_cmd -t $table -F $name", 1); +# if command fails, then send output to syslog +sub run_cmd { + my ($cmd_to_run, $redirect) = @_; + + log_msg("Running: $cmd_to_run"); + + if ($redirect) { + open (my $out, '-|', $cmd_to_run . ' 2>&1') + or die "Can't run command \"$cmd_to_run\": $!"; + my @cmd_out = <$out>; + + # if command suceeds to do nothing. + return if (close ($out)); + + foreach my $line (@cmd_out) { + chomp $line; + syslog(LOG_INFO, "%s", $line); + } + } else { + system($cmd_to_run); + } +} + # end of file -- cgit v1.2.3