line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::POPRelay::Daemon; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
999
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
10
|
use Mail::POPRelay; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
5
|
1
|
|
|
1
|
|
1518
|
use File::Tail; |
|
1
|
|
|
|
|
72554
|
|
|
1
|
|
|
|
|
79
|
|
6
|
1
|
|
|
1
|
|
11
|
use vars qw[@ISA $VERSION ]; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
62
|
|
7
|
1
|
|
|
1
|
|
982
|
use POSIX qw[setsid ]; |
|
1
|
|
|
|
|
17386
|
|
|
1
|
|
|
|
|
7
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
@ISA = qw[Mail::POPRelay ]; |
10
|
|
|
|
|
|
|
$VERSION = '0.1.1'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# trap signals |
14
|
|
|
|
|
|
|
# --------- |
15
|
|
|
|
|
|
|
sub __setupSignals { |
16
|
0
|
|
|
0
|
|
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
0
|
|
|
$SIG{'TERM'} = sub { $self->wipeRelayDirectory(); $self->generateRelayFile(); }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
19
|
0
|
|
|
0
|
|
|
$SIG{'KILL'} = sub { $self->wipeRelayDirectory(); $self->generateRelayFile(); }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$SIG{'HUP'} = sub { |
21
|
0
|
|
|
0
|
|
|
$self->initWithConfigFile($self->{'configFile'}); |
22
|
0
|
|
|
|
|
|
$self->cleanRelayDirectory(); |
23
|
0
|
|
|
|
|
|
$self->generateRelayFile(); |
24
|
0
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# daemonize |
29
|
|
|
|
|
|
|
# --------- |
30
|
|
|
|
|
|
|
sub init { |
31
|
0
|
|
|
0
|
0
|
|
my $self = Mail::POPRelay::initWithConfigFile(@_); |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
defined(my $pid = fork()) or die "Unable to fork: $!"; |
34
|
0
|
0
|
|
|
|
|
if ($pid) { |
35
|
|
|
|
|
|
|
# parent |
36
|
0
|
|
|
|
|
|
return $pid; |
37
|
|
|
|
|
|
|
} else { |
38
|
|
|
|
|
|
|
# sibling |
39
|
|
|
|
|
|
|
#chdir('/') or die "Can't chdir to /: $!"; |
40
|
0
|
0
|
|
|
|
|
setsid() or die "Can't start new session: $!"; |
41
|
0
|
0
|
|
|
|
|
open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
$self->__setupSignals(); |
44
|
0
|
|
|
|
|
|
$self->__mainLoop(); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# --------- |
52
|
|
|
|
|
|
|
sub __mainLoop { |
53
|
0
|
|
|
0
|
|
|
my $self = shift; |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
my $fileTail = File::Tail->new ( |
56
|
|
|
|
|
|
|
name => $self->{'mailLogFile'}, |
57
|
|
|
|
|
|
|
interval => 2, |
58
|
|
|
|
|
|
|
maxinterval => 3, |
59
|
|
|
|
|
|
|
adjustafter => 3, |
60
|
|
|
|
|
|
|
) or die "Unable to tail $self->{'mailLogFile'}: $!"; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my($line, $flag); |
63
|
0
|
|
|
|
|
|
while (defined($line = $fileTail->read())) { |
64
|
0
|
0
|
|
|
|
|
if ($line =~ m|$self->{'mailLogRegExp'}|) { |
65
|
|
|
|
|
|
|
# save processing cycles and exit early if possible |
66
|
0
|
|
|
|
|
|
$flag = 0; |
67
|
0
|
0
|
|
|
|
|
$flag = 1 if $self->addRelayAddress($1, $2); |
68
|
0
|
0
|
|
|
|
|
$flag = 1 if $self->cleanRelayDirectory(); |
69
|
0
|
0
|
|
|
|
|
$self->generateRelayFile() if $flag; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
|
$self->wipeRelayDirectory(); |
74
|
0
|
|
|
|
|
|
$self->generateRelayFile(); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1337; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |