line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XAS::Logmon::Input::Tail::Linux; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1430
|
use Linux::Inotify2; |
|
1
|
|
|
|
|
1894
|
|
|
1
|
|
|
|
|
131
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use XAS::Class |
8
|
1
|
|
|
|
|
10
|
debug => 0, |
9
|
|
|
|
|
|
|
version => $VERSION, |
10
|
|
|
|
|
|
|
base => 'XAS::Base', |
11
|
|
|
|
|
|
|
utils => 'dotid', |
12
|
|
|
|
|
|
|
mutators => '_in_move _in_modify _in_delete _in_create', |
13
|
|
|
|
|
|
|
constant => { |
14
|
|
|
|
|
|
|
FMASK => IN_MODIFY | IN_MOVE_SELF | IN_DELETE_SELF, |
15
|
|
|
|
|
|
|
DMASK => IN_CREATE | IN_MOVED_FROM | IN_MOVED_TO, |
16
|
|
|
|
|
|
|
}, |
17
|
|
|
|
|
|
|
mixins => 'get init_notifier FMASK DMASK _in_move _in_modify _in_delete |
18
|
|
|
|
|
|
|
_in_create _set_watchers _set_file_watcher _set_dir_watcher', |
19
|
1
|
|
|
1
|
|
6
|
; |
|
1
|
|
|
|
|
0
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
22
|
|
|
|
|
|
|
# Public Methods |
23
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub get { |
26
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
if (scalar(@{$self->{'buffer'}})){ |
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
$self->log->debug('processing...'); |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
return shift @{$self->{'buffer'}}; |
|
0
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
} else { |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
$self->log->debug('waiting...'); |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
while (my $count = $self->notifier->poll()) { |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$self->log->debug('processing...'); |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
last if ($self->_in_delete); |
43
|
0
|
0
|
|
|
|
|
last if ($self->_in_move); |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
next if ($self->_in_create); |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
if ($self->_in_modify) { |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if (scalar(@{$self->{'buffer'}})) { |
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return shift @{$self->{'buffer'}}; |
|
0
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return undef; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub init_notifier { |
66
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$self->_in_move(0); |
69
|
0
|
|
|
|
|
|
$self->_in_modify(0); |
70
|
0
|
|
|
|
|
|
$self->_in_delete(0); |
71
|
0
|
|
|
|
|
|
$self->_in_create(0); |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
$self->{'notifier'} = Linux::Inotify2->new() or |
74
|
|
|
|
|
|
|
$self->throw_msg( |
75
|
|
|
|
|
|
|
dotid($self->class) . '.inotify', |
76
|
|
|
|
|
|
|
'logmon_notifier', |
77
|
|
|
|
|
|
|
$! |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$self->_set_watchers(); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
85
|
|
|
|
|
|
|
# Private Methods |
86
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _set_watchers { |
89
|
0
|
|
|
0
|
|
|
my $self = shift; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
$self->_set_file_watcher; |
92
|
0
|
|
|
|
|
|
$self->_set_dir_watcher; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _set_file_watcher { |
97
|
0
|
|
|
0
|
|
|
my $self = shift; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$self->notifier->watch( |
100
|
|
|
|
|
|
|
$self->filename->path, |
101
|
|
|
|
|
|
|
FMASK, |
102
|
|
|
|
|
|
|
sub { |
103
|
0
|
|
|
0
|
|
|
my $event = shift; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
$self->_in_move(0); |
106
|
0
|
|
|
|
|
|
$self->_in_modify(0); |
107
|
0
|
|
|
|
|
|
$self->_in_delete(0); |
108
|
0
|
|
|
|
|
|
$self->_in_create(0); |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
if ($event->IN_MODIFY) { |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
$self->log->debug('IN_MODIFY'); |
113
|
0
|
|
|
|
|
|
$self->_in_modify(1); |
114
|
0
|
|
|
|
|
|
$self->_do_tail(); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
if ($event->IN_DELETE_SELF) { |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
$self->log->debug('IN_DELETE_SELF'); |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$event->w->cancel; |
123
|
0
|
|
|
|
|
|
$self->_in_delete(1); |
124
|
0
|
0
|
|
|
|
|
$self->statefile->delete if ($self->statefile->exists); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
} |
129
|
0
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub _set_dir_watcher { |
134
|
0
|
|
|
0
|
|
|
my $self = shift; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
$self->notifier->watch( |
137
|
|
|
|
|
|
|
$self->filename->directory, |
138
|
|
|
|
|
|
|
DMASK, |
139
|
|
|
|
|
|
|
sub { |
140
|
0
|
|
|
0
|
|
|
my $event = shift; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
$self->_in_move(0); |
143
|
0
|
|
|
|
|
|
$self->_in_modify(0); |
144
|
0
|
|
|
|
|
|
$self->_in_delete(0); |
145
|
0
|
|
|
|
|
|
$self->_in_create(0); |
146
|
|
|
|
|
|
|
|
147
|
0
|
0
|
0
|
|
|
|
if ($event->IN_MOVED_FROM && |
148
|
|
|
|
|
|
|
($event->fullname eq $self->filename->path)) { |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
$self->log->debug('IN_MOVED_FROM'); |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
$event->w->cancel; |
153
|
0
|
|
|
|
|
|
$self->_in_move(1); |
154
|
0
|
0
|
|
|
|
|
$self->statefile->delete if ($self->statefile->exists); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
0
|
0
|
0
|
|
|
|
if ($event->IN_MOVED_TO && |
159
|
|
|
|
|
|
|
($event->fullname eq $self->filename->path)) { |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
$self->log->debug('IN_MOVED_TO'); |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
$self->_write_state(0); |
164
|
0
|
|
|
|
|
|
$self->_set_file_watcher; |
165
|
0
|
|
|
|
|
|
$self->_in_create(1); |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
0
|
0
|
0
|
|
|
|
if ($event->IN_CREATE && |
170
|
|
|
|
|
|
|
($event->fullname eq $self->filename->path)) { |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
$self->log->debug('IN_CREATE'); |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
$self->_write_state(0); |
175
|
0
|
|
|
|
|
|
$self->_set_file_watcher; |
176
|
0
|
|
|
|
|
|
$self->_in_create(1); |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
} |
181
|
0
|
|
|
|
|
|
); |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
1; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
__END__ |