| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# iqbi-damiq - launcher for Algorithm::EventsPerSecond::Sukkal |
|
4
|
|
|
|
|
|
|
|
|
5
|
6
|
|
|
6
|
|
22395
|
use 5.006; |
|
|
6
|
|
|
|
|
13
|
|
|
6
|
6
|
|
|
6
|
|
21
|
use strict; |
|
|
6
|
|
|
|
|
5
|
|
|
|
6
|
|
|
|
|
104
|
|
|
7
|
6
|
|
|
6
|
|
42
|
use warnings; |
|
|
6
|
|
|
|
|
6
|
|
|
|
6
|
|
|
|
|
227
|
|
|
8
|
6
|
|
|
6
|
|
3739
|
use Getopt::Long qw(GetOptions); |
|
|
6
|
|
|
|
|
71522
|
|
|
|
6
|
|
|
|
|
25
|
|
|
9
|
6
|
|
|
6
|
|
3489
|
use Pod::Usage qw(pod2usage); |
|
|
6
|
|
|
|
|
316010
|
|
|
|
6
|
|
|
|
|
365
|
|
|
10
|
6
|
|
|
6
|
|
2404
|
use Algorithm::EventsPerSecond; |
|
|
6
|
|
|
|
|
16
|
|
|
|
6
|
|
|
|
|
197
|
|
|
11
|
6
|
|
|
6
|
|
2551
|
use Algorithm::EventsPerSecond::Sukkal; |
|
|
6
|
|
|
|
|
16
|
|
|
|
6
|
|
|
|
|
345955
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my ( |
|
14
|
6
|
|
|
|
|
290804
|
$socket, $window, $max_keys, $max_key_length, $idle_timeout, $sweep_interval, |
|
15
|
|
|
|
|
|
|
$max_clients, $mode, $daemonize, $pidfile, $require_xs, |
|
16
|
|
|
|
|
|
|
); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
GetOptions( |
|
19
|
|
|
|
|
|
|
'socket|s=s' => \$socket, |
|
20
|
|
|
|
|
|
|
'require-xs|x' => \$require_xs, |
|
21
|
|
|
|
|
|
|
'window|w=i' => \$window, |
|
22
|
|
|
|
|
|
|
'max-keys=i' => \$max_keys, |
|
23
|
|
|
|
|
|
|
'max-key-length=i' => \$max_key_length, |
|
24
|
|
|
|
|
|
|
'idle-timeout=i' => \$idle_timeout, |
|
25
|
|
|
|
|
|
|
'sweep-interval=i' => \$sweep_interval, |
|
26
|
|
|
|
|
|
|
'max-clients=i' => \$max_clients, |
|
27
|
|
|
|
|
|
|
'mode|m=s' => \$mode, |
|
28
|
|
|
|
|
|
|
'daemonize|d' => \$daemonize, |
|
29
|
|
|
|
|
|
|
'pidfile|p=s' => \$pidfile, |
|
30
|
1
|
|
|
1
|
|
1119
|
'help|h' => sub { pod2usage( -exitval => 0, -verbose => 1 ) }, |
|
31
|
|
|
|
|
|
|
'version|v' => sub { |
|
32
|
1
|
|
|
1
|
|
1162
|
print "iqbi-damiq (Algorithm::EventsPerSecond::Sukkal) " . "$Algorithm::EventsPerSecond::Sukkal::VERSION\n"; |
|
33
|
1
|
|
|
|
|
113
|
exit 0; |
|
34
|
|
|
|
|
|
|
}, |
|
35
|
6
|
100
|
|
|
|
79
|
) or pod2usage( -exitval => 2 ); |
|
36
|
|
|
|
|
|
|
|
|
37
|
3
|
100
|
|
|
|
3806
|
pod2usage( -exitval => 2, -message => "iqbi-damiq: --socket is required\n" ) |
|
38
|
|
|
|
|
|
|
unless defined $socket; |
|
39
|
|
|
|
|
|
|
|
|
40
|
2
|
100
|
66
|
|
|
15
|
die "iqbi-damiq: --require-xs given but the " . Algorithm::EventsPerSecond->backend . " backend is loaded, not XS\n" |
|
41
|
|
|
|
|
|
|
if $require_xs && Algorithm::EventsPerSecond->backend ne 'XS'; |
|
42
|
|
|
|
|
|
|
|
|
43
|
1
|
50
|
|
|
|
15
|
my $sukkal = Algorithm::EventsPerSecond::Sukkal->new( |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
socket => $socket, |
|
45
|
|
|
|
|
|
|
( defined $window ? ( window => $window ) : () ), |
|
46
|
|
|
|
|
|
|
( defined $max_keys ? ( max_keys => $max_keys ) : () ), |
|
47
|
|
|
|
|
|
|
( defined $max_key_length ? ( max_key_length => $max_key_length ) : () ), |
|
48
|
|
|
|
|
|
|
( defined $idle_timeout ? ( idle_timeout => $idle_timeout ) : () ), |
|
49
|
|
|
|
|
|
|
( defined $sweep_interval ? ( sweep_interval => $sweep_interval ) : () ), |
|
50
|
|
|
|
|
|
|
( defined $max_clients ? ( max_clients => $max_clients ) : () ), |
|
51
|
|
|
|
|
|
|
( defined $mode ? ( socket_mode => $mode ) : () ), |
|
52
|
|
|
|
|
|
|
); |
|
53
|
|
|
|
|
|
|
|
|
54
|
1
|
50
|
|
|
|
2
|
if ($daemonize) { |
|
55
|
0
|
|
|
|
|
0
|
require POSIX; |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
0
|
defined( my $pid = fork ) or die "iqbi-damiq: cannot fork: $!\n"; |
|
58
|
0
|
0
|
|
|
|
0
|
exit 0 if $pid; |
|
59
|
0
|
0
|
|
|
|
0
|
POSIX::setsid() != -1 or die "iqbi-damiq: setsid failed: $!\n"; |
|
60
|
0
|
0
|
|
|
|
0
|
defined( $pid = fork ) or die "iqbi-damiq: cannot fork: $!\n"; |
|
61
|
0
|
0
|
|
|
|
0
|
exit 0 if $pid; |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
0
|
chdir '/'; |
|
64
|
0
|
|
|
|
|
0
|
open STDIN, '<', '/dev/null'; |
|
65
|
0
|
|
|
|
|
0
|
open STDOUT, '>', '/dev/null'; |
|
66
|
0
|
|
|
|
|
0
|
open STDERR, '>', '/dev/null'; |
|
67
|
|
|
|
|
|
|
} ## end if ($daemonize) |
|
68
|
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
2
|
my $pidfile_owner; |
|
70
|
1
|
50
|
|
|
|
3
|
if ( defined $pidfile ) { |
|
71
|
1
|
50
|
|
|
|
228
|
open my $fh, '>', $pidfile |
|
72
|
|
|
|
|
|
|
or die "iqbi-damiq: cannot write pidfile $pidfile: $!\n"; |
|
73
|
1
|
|
|
|
|
21
|
print $fh "$$\n"; |
|
74
|
1
|
|
|
|
|
44
|
close $fh; |
|
75
|
1
|
|
|
|
|
8
|
$pidfile_owner = $$; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
END { |
|
79
|
6
|
50
|
66
|
6
|
|
|
unlink $pidfile |
|
|
|
|
66
|
|
|
|
|
|
80
|
|
|
|
|
|
|
if defined $pidfile && defined $pidfile_owner && $$ == $pidfile_owner; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
1
|
|
|
1
|
|
20
|
$SIG{INT} = $SIG{TERM} = sub { $sukkal->stop }; |
|
|
1
|
|
|
|
|
2804
|
|
|
84
|
1
|
|
|
|
|
6
|
$SIG{HUP} = 'IGNORE'; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
printf "iqbi-damiq: serving %s (window=%ds, backend=%s)\n", |
|
87
|
1
|
50
|
|
|
|
12
|
$socket, $sukkal->{window}, Algorithm::EventsPerSecond->backend |
|
88
|
|
|
|
|
|
|
unless $daemonize; |
|
89
|
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
5
|
$sukkal->run; |
|
91
|
|
|
|
|
|
|
|
|
92
|
1
|
50
|
|
|
|
5
|
print "iqbi-damiq: shut down\n" unless $daemonize; |
|
93
|
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
73
|
exit 0; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |