Skip to content

Commit c865e68

Browse files
committed
hawk.pl: Handle SIGINT
When interrupted also stop the tail child process. Version 7.2 Signed-off-by: Marian Marinov <mm@yuhu.biz>
1 parent a19951c commit c865e68

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

hawk.pl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
my $pgsql_available=1;
1818
my $sqlite_available=1;
1919
my $debug = 0;
20+
my $tail_pid = 0;
2021
$ENV{PATH} = ''; # remove unsecure path
21-
my $VERSION = '7.1';
22+
my $VERSION = '7.2';
2223

2324
use lib '/usr/lib/hawk/';
2425
use POSIX qw(setsid), qw(strftime), qw(WNOHANG);
@@ -28,6 +29,7 @@
2829
eval "use DBD::SQLite; 1" or $sqlite_available = 0;
2930

3031
$SIG{"CHLD"} = \&sigChld;
32+
$SIG{"INT"} = \&sigINT;
3133
$SIG{__DIE__} = sub { logger(@_); };
3234

3335

@@ -111,6 +113,14 @@ sub sigChld {
111113
}
112114
}
113115

116+
# Kill children and exit
117+
118+
sub sigINT {
119+
kill 'INT', $tail_pid;
120+
logger("Quiting");
121+
exit 0;
122+
}
123+
114124
# If $_[3] is 0, store the failed login attempt to the DB
115125
# If $_[3] is 1, store the bruteforce attempt to the DB
116126
# The brootforce table is later checked by the cron
@@ -455,7 +465,6 @@ sub main {
455465
die("Error: no valid file found in monitor_list file list: $config{'monitor_list'}\n");
456466
}
457467
my $log_list = "/usr/bin/sudo /usr/bin/tail -s 1.00 -F --max-unchanged-stats=30 $monitor_list |";
458-
#my $log_list = "/usr/bin/tail -s 1.00 -F --max-unchanged-stats=30 $monitor_list |";
459468

460469
if ($debug) {
461470
# service_ids=ftp:0 ssh:1 pop3:2 imap:3 webmail:4 cpanel:5 da:6
@@ -535,7 +544,7 @@ sub main {
535544
}
536545

537546
# use tail to open all logs that should be monitored
538-
open LOGS, $log_list or die "open $log_list failed: $!\n";
547+
$tail_pid = open LOGS, $log_list or die "open $log_list failed: $!\n";
539548

540549
# make the output of the opened logs unbuffered
541550
select((select(HAWKLOG), $| = 1)[0]);
@@ -894,7 +903,7 @@ =head2 write_pid() - Write the new hawk pid to the pid file
894903
0 on failure
895904
1 on success
896905
897-
=head2 sigChld() - Reaper of the dead childs
906+
=head2 sigChld() - Reaper of the dead children
898907
899908
Called only in case of SIG CHILD
900909

0 commit comments

Comments
 (0)