1
0
mirror of https://git.FreeBSD.org/ports.git synced 2025-01-03 06:04:53 +00:00
freebsd-ports/security/swatch/files/patch-swatch-2
Cheng-Lung Sung 2f8e7a283a - I forgot to add this patch into cvs
PR:		ports/109370
2007-02-22 09:58:40 +00:00

127 lines
3.4 KiB
Plaintext

--- swatch.orig 2006-07-21 14:55:00.000000000 -0600
+++ swatch 2006-08-24 17:02:03.000000000 -0600
@@ -404,12 +404,16 @@
\$/ = "$opt_input_record_separator";
my \$swatch_flush_interval = 300;
my \$swatch_last_flush = time;
+my \$tail_pid = -1;
use IO::Handle;
STDOUT->autoflush(1);
sub goodbye {
\$| = 0;
+ if( \$tail_pid != -1 ) {
+ kill('TERM', \$tail_pid);
+ }
];
if ($opt_read_pipe) {
@@ -517,7 +521,8 @@
}
$code = qq/
my \$filename = '$filename';
-if (not open(TAIL, \"$tail_cmd_name $tail_cmd_args \$filename|\")) {
+\$tail_pid = open(TAIL, \"$tail_cmd_name $tail_cmd_args \$filename|\");
+if (not \$tail_pid) {
die "$0: cannot read run \\"$tail_cmd_name $tail_cmd_args \$filename\\": \$!\\n";
}
@@ -543,6 +548,7 @@
my $code;
$code = q[
}
+## TODO: Add close !!!
];
return $code;
}
--- lib/Swatch/Throttle.pm.orig 2004-07-19 22:14:54.000000000 +0200
+++ lib/Swatch/Throttle.pm 2006-01-02 17:06:14.000000000 +0100
@@ -95,6 +95,7 @@
@_
);
+ my @delay = split(/:/, "0:$opts{DELAY}");
my @dmyhms;
my $key;
my $cur_rec;
@@ -134,30 +135,61 @@
$rec->{FIRST} = [ @dmyhms ];
$rec->{LAST} = [ @dmyhms ];
$rec->{HOLD_DHMS} = $opts{HOLD_DHMS} if defined $opts{HOLD_DHMS};
- $rec->{COUNT} = 1;
+ $rec->{COUNT} = 0;
$LogRecords{$key} = $rec;
- return $msg;
- } else {
- $cur_rec = $LogRecords{$key};
- $cur_rec->{COUNT}++;
- if (defined $opts{THRESHOLD} and $cur_rec->{COUNT} == $opts{THRESHOLD}) {
- ## threshold exceeded ##
- chomp $msg;
- $msg = "$msg (threshold $opts{THRESHOLD} exceeded)";
- $cur_rec->{COUNT} = 0;
- } elsif (defined $opts{HOLD_DHMS}
- and past_hold_time($cur_rec->{LAST},
- \@dmyhms, $opts{HOLD_DHMS})) {
+ }
+
+ ## Get current record ##
+ $cur_rec = $LogRecords{$key};
+ $cur_rec->{COUNT}++;
+
+ ## delay only ##
+ if( defined $opts{DELAY} and not defined $opts{THRESHOLD} ) {
+ if( past_hold_time($cur_rec->{LAST}, [ @dmyhms ], [ @delay ]) ) {
## hold time exceeded ##
chomp $msg;
$msg = "$msg (seen $cur_rec->{COUNT} times)";
- $cur_rec->{COUNT} = 0;
+ $cur_rec->{COUNT} = 1;
$cur_rec->{LAST} = [ @dmyhms ];
} else {
$msg = '';
}
- $LogRecords{$key} = $cur_rec if exists($LogRecords{$key}); ## save any new values ##
+
+ ## threshold only ##
+ } elsif( defined $opts{THRESHOLD} and not defined $opts{DELAY} ) {
+ if( $cur_rec->{COUNT} == $opts{THRESHOLD}) {
+ ## threshold exceeded ##
+ chomp $msg;
+ $msg = "$msg (threshold $opts{THRESHOLD} exceeded)";
+ $cur_rec->{COUNT} = 0;
+ } else {
+ $msg = '';
+ }
+
+ ## threshold AND delay ##
+ } elsif( defined $opts{THRESHOLD} and defined $opts{DELAY} ) {
+ if( not past_hold_time($cur_rec->{LAST}, [ @dmyhms ], [ @delay ]) ) {
+ if( $cur_rec->{COUNT} == $opts{THRESHOLD} ) {
+ ## threshold exceeded during delay ##
+ chomp $msg;
+ $msg = "$msg (threshold $opts{THRESHOLD} exceeded during delay $opts{DELAY})";
+
+ ## TODO: Tenir compte du parametre repeat ici ##
+ $cur_rec->{COUNT} = 0;
+ $cur_rec->{LAST} = [ @dmyhms ];
+ } else {
+ $msg = '';
+ }
+ } else {
+ $cur_rec->{COUNT} = 1;
+ $cur_rec->{LAST} = [ @dmyhms ];
+ $msg = '';
+ }
}
+
+ ## save any new values ##
+ $LogRecords{$key} = $cur_rec if exists($LogRecords{$key});
+
return $msg;
}