line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Usul::IPC; |
2
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
118
|
use namespace::autoclean; |
|
18
|
|
|
|
|
41
|
|
|
18
|
|
|
|
|
151
|
|
4
|
|
|
|
|
|
|
|
5
|
18
|
|
|
18
|
|
1354
|
use Class::Null; |
|
18
|
|
|
|
|
54
|
|
|
18
|
|
|
|
|
435
|
|
6
|
18
|
|
|
18
|
|
102
|
use Class::Usul::Constants qw( EXCEPTION_CLASS FALSE NUL OK SPC TRUE ); |
|
18
|
|
|
|
|
39
|
|
|
18
|
|
|
|
|
177
|
|
7
|
18
|
|
|
|
|
129
|
use Class::Usul::Functions qw( arg_list get_user io loginid |
8
|
18
|
|
|
18
|
|
15896
|
merge_attributes throw ); |
|
18
|
|
|
|
|
39
|
|
9
|
18
|
|
|
18
|
|
33136
|
use Class::Usul::IPC::Cmd; |
|
18
|
|
|
|
|
109
|
|
|
18
|
|
|
|
|
157
|
|
10
|
18
|
|
|
18
|
|
212
|
use Class::Usul::Time qw( time2str ); |
|
18
|
|
|
|
|
69
|
|
|
18
|
|
|
|
|
1511
|
|
11
|
18
|
|
|
18
|
|
176
|
use Class::Usul::Types qw( Bool ConfigProvider Logger ); |
|
18
|
|
|
|
|
55
|
|
|
18
|
|
|
|
|
260
|
|
12
|
18
|
|
|
18
|
|
36678
|
use English qw( -no_match_vars ); |
|
18
|
|
|
|
|
68
|
|
|
18
|
|
|
|
|
179
|
|
13
|
18
|
|
|
18
|
|
10806
|
use Module::Load::Conditional qw( can_load ); |
|
18
|
|
|
|
|
71
|
|
|
18
|
|
|
|
|
1396
|
|
14
|
18
|
|
|
18
|
|
189
|
use Unexpected::Functions qw( Unspecified ); |
|
18
|
|
|
|
|
52
|
|
|
18
|
|
|
|
|
227
|
|
15
|
18
|
|
|
18
|
|
7797
|
use Moo; |
|
18
|
|
|
|
|
54
|
|
|
18
|
|
|
|
|
188
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Public attributes |
18
|
|
|
|
|
|
|
has 'cache_ttys' => is => 'ro', isa => Bool, default => TRUE; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'config' => is => 'ro', isa => ConfigProvider, required => TRUE; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'log' => is => 'ro', isa => Logger, required => TRUE; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Private functions |
25
|
|
|
|
|
|
|
my $_cmd_matches = sub { |
26
|
|
|
|
|
|
|
my ($cmd, $pattern) = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return !$pattern || $cmd =~ m{ $pattern }msx ? TRUE : FALSE; |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $_new_proc_process_table = sub { |
32
|
|
|
|
|
|
|
my $cache_ttys = shift; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
can_load( modules => { 'Proc::ProcessTable' => '0' } ) |
35
|
|
|
|
|
|
|
and return Proc::ProcessTable->new( cache_ttys => $cache_ttys ); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return Class::Null->new; |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $_proc_belongs_to_user = sub { |
41
|
|
|
|
|
|
|
my ($puid, $user) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return (!$user || $user eq 'All' || $user eq loginid $puid) ? TRUE : FALSE; |
44
|
|
|
|
|
|
|
}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $_pscomp = sub { |
47
|
|
|
|
|
|
|
my ($arg1, $arg2) = @_; my $result; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$result = $arg1->{uid} cmp $arg2->{uid}; |
50
|
|
|
|
|
|
|
$result = $arg1->{pid} <=> $arg2->{pid} if ($result == 0); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
return $result; |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $_set_fields = sub { |
56
|
|
|
|
|
|
|
my ($has, $p) = @_; my $flds = {}; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$flds->{id } = $has->{pid } ? $p->pid : NUL; |
59
|
|
|
|
|
|
|
$flds->{pid } = $has->{pid } ? $p->pid : NUL; |
60
|
|
|
|
|
|
|
$flds->{ppid } = $has->{ppid } ? $p->ppid : NUL; |
61
|
|
|
|
|
|
|
$flds->{start} = $has->{start } ? time2str( '%d/%m %H:%M', $p->start ) : NUL; |
62
|
|
|
|
|
|
|
$flds->{state} = $has->{state } ? $p->state : NUL; |
63
|
|
|
|
|
|
|
$flds->{tty } = $has->{ttydev} ? $p->ttydev : NUL; |
64
|
|
|
|
|
|
|
$flds->{time } = $has->{time } ? int $p->time / 1_000_000 : NUL; |
65
|
|
|
|
|
|
|
$flds->{uid } = $has->{uid } ? getpwuid $p->uid : NUL; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
if ($has->{ttydev} and $p->ttydev) { |
68
|
|
|
|
|
|
|
$flds->{tty} = $p->ttydev; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
elsif ($has->{ttynum} and $p->ttynum) { |
71
|
|
|
|
|
|
|
$flds->{tty} = $p->ttynum; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else { $flds->{tty} = NUL } |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
if ($has->{rss} and $p->rss) { |
76
|
|
|
|
|
|
|
$flds->{size} = int $p->rss/1_024; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
elsif ($has->{size} and $p->size) { |
79
|
|
|
|
|
|
|
$flds->{size} = int $p->size/1_024; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else { $flds->{size} = NUL } |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
if ($has->{exec} and $p->exec) { |
84
|
|
|
|
|
|
|
$flds->{cmd} = substr $p->exec, 0, 64; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
elsif ($has->{cmndline} and $p->cmndline) { |
87
|
|
|
|
|
|
|
$flds->{cmd} = substr $p->cmndline, 0, 64; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
elsif ($has->{fname} and $p->fname) { |
90
|
|
|
|
|
|
|
$flds->{cmd} = substr $p->fname, 0, 64; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
else { $flds->{cmd} = NUL } |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
return $flds; |
95
|
|
|
|
|
|
|
}; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $_signal_cmd = sub { |
98
|
|
|
|
|
|
|
my ($cmd, $flag, $sig, $pids) = @_; my $opts = []; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
$sig and push @{ $opts }, '-o', "sig=${sig}"; |
101
|
|
|
|
|
|
|
$flag and push @{ $opts }, '-o', 'flag=one'; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
return [ $cmd, '-nc', 'signal_process', @{ $opts }, '--', @{ $pids || [] } ]; |
104
|
|
|
|
|
|
|
}; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Construction |
107
|
|
|
|
|
|
|
around 'BUILDARGS' => sub { |
108
|
|
|
|
|
|
|
my ($orig, $self, @args) = @_; my $attr = $orig->( $self, @args ); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $builder = $attr->{builder} or return $attr; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
merge_attributes $attr, $builder, [ 'config', 'log' ]; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
return $attr; |
115
|
|
|
|
|
|
|
}; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my $_new_process_table = sub { |
118
|
|
|
|
|
|
|
my ($self, $rows, $count) = @_; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
return { |
121
|
|
|
|
|
|
|
count => $count, |
122
|
|
|
|
|
|
|
fields => [ qw( uid pid ppid start time size state tty cmd ) ], |
123
|
|
|
|
|
|
|
labels => { uid => 'User', pid => 'PID', |
124
|
|
|
|
|
|
|
ppid => 'PPID', start => 'Start Time', |
125
|
|
|
|
|
|
|
tty => 'TTY', time => 'Time', |
126
|
|
|
|
|
|
|
size => 'Size', state => 'State', |
127
|
|
|
|
|
|
|
cmd => 'Command' }, |
128
|
|
|
|
|
|
|
typelist => { pid => 'numeric', ppid => 'numeric', |
129
|
|
|
|
|
|
|
start => 'date', size => 'numeric', |
130
|
|
|
|
|
|
|
time => 'numeric' }, |
131
|
|
|
|
|
|
|
values => $rows, |
132
|
|
|
|
|
|
|
wrap => { cmd => 1 }, |
133
|
|
|
|
|
|
|
}; |
134
|
|
|
|
|
|
|
}; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# Public methods |
137
|
|
|
|
|
|
|
sub child_list { |
138
|
0
|
|
|
0
|
1
|
0
|
my ($self, $pid, $procs) = @_; my ($child, $ppt); my @pids = (); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
139
|
|
|
|
|
|
|
|
140
|
0
|
0
|
|
|
|
0
|
unless (defined $procs) { |
141
|
0
|
|
|
|
|
0
|
$ppt = $_new_proc_process_table->( $self->cache_ttys ); |
142
|
0
|
|
|
|
|
0
|
$procs = { map { $_->pid => $_->ppid } @{ $ppt->table } }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
0
|
0
|
|
|
|
0
|
if (exists $procs->{ $pid }) { |
146
|
0
|
|
|
|
|
0
|
for $child (grep { $procs->{ $_ } == $pid } keys %{ $procs }) { |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
147
|
0
|
|
|
|
|
0
|
push @pids, $self->child_list( $child, $procs ); # Recurse |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
0
|
push @pids, $pid; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
0
|
return sort { $a <=> $b } @pids; |
|
0
|
|
|
|
|
0
|
|
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub list_pids_by_file_system { |
157
|
0
|
0
|
|
0
|
1
|
0
|
my ($self, $fsystem) = @_; $fsystem or return (); |
|
0
|
|
|
|
|
0
|
|
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
0
|
my $opts = { err => 'null', expected_rv => 1 }; |
160
|
|
|
|
|
|
|
# TODO: Make fuser OS dependent |
161
|
0
|
|
0
|
|
|
0
|
my $data = $self->run_cmd( "fuser ${fsystem}", $opts )->out || NUL; |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
0
|
$data =~ s{ [^0-9\s] }{}gmx; $data =~ s{ \s+ }{ }gmx; |
|
0
|
|
|
|
|
0
|
|
164
|
|
|
|
|
|
|
|
165
|
0
|
0
|
|
|
|
0
|
return sort { $a <=> $b } grep { defined && length } split SPC, $data; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub popen { |
169
|
98
|
|
|
98
|
1
|
386526
|
return shift->run_cmd( @_ ); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub process_exists { |
173
|
0
|
|
|
0
|
1
|
0
|
my ($self, @args) = @_; my $args = arg_list @args; |
|
0
|
|
|
|
|
0
|
|
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
0
|
my $pid = $args->{pid}; my ($io, $file); |
|
0
|
|
|
|
|
0
|
|
176
|
|
|
|
|
|
|
|
177
|
0
|
0
|
0
|
|
|
0
|
$file = $args->{file} and $io = io( $file ) and $io->is_file |
|
|
|
0
|
|
|
|
|
178
|
|
|
|
|
|
|
and $pid = $io->chomp->lock->getline; |
179
|
|
|
|
|
|
|
|
180
|
0
|
0
|
0
|
|
|
0
|
(not $pid or $pid !~ m{ \d+ }mx) and return FALSE; |
181
|
|
|
|
|
|
|
|
182
|
0
|
0
|
|
|
|
0
|
return (CORE::kill 0, $pid) ? TRUE : FALSE; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub process_table { |
186
|
0
|
|
|
0
|
1
|
0
|
my ($self, @args) = @_; my $args = arg_list @args; |
|
0
|
|
|
|
|
0
|
|
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
0
|
my $pat = $args->{pattern}; |
189
|
0
|
|
0
|
|
|
0
|
my $ptype = $args->{type } // 1; |
190
|
0
|
|
0
|
|
|
0
|
my $user = $args->{user } // get_user->name; |
191
|
0
|
|
|
|
|
0
|
my $ppt = $_new_proc_process_table->( $self->cache_ttys ); |
192
|
0
|
|
|
|
|
0
|
my $has = { map { $_ => TRUE } $ppt->fields }; |
|
0
|
|
|
|
|
0
|
|
193
|
0
|
|
|
|
|
0
|
my @rows = (); |
194
|
0
|
|
|
|
|
0
|
my $count = 0; |
195
|
|
|
|
|
|
|
|
196
|
0
|
0
|
|
|
|
0
|
if ($ptype == 3) { |
197
|
0
|
|
|
|
|
0
|
my %procs = map { $_->pid => $_ } @{ $ppt->table }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
198
|
0
|
|
|
|
|
0
|
my @pids = $self->list_pids_by_file_system( $args->{fsystem} ); |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
0
|
for my $p (grep { defined } map { $procs{ $_ } } @pids) { |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
201
|
0
|
|
|
|
|
0
|
push @rows, $_set_fields->( $has, $p ); |
202
|
0
|
|
|
|
|
0
|
$count++; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
else { |
206
|
0
|
|
|
|
|
0
|
for my $p (@{ $ppt->table }) { |
|
0
|
|
|
|
|
0
|
|
207
|
0
|
0
|
0
|
|
|
0
|
if ( ($ptype == 1 and $_proc_belongs_to_user->( $p->uid, $user )) |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
208
|
|
|
|
|
|
|
or ($ptype == 2 and $_cmd_matches->( $p->cmndline, $pat ))) { |
209
|
0
|
|
|
|
|
0
|
push @rows, $_set_fields->( $has, $p ); |
210
|
0
|
|
|
|
|
0
|
$count++; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
return $self->$_new_process_table |
216
|
0
|
|
|
|
|
0
|
( [ sort { $_pscomp->( $a, $b ) } @rows ], $count ); |
|
0
|
|
|
|
|
0
|
|
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub run_cmd { |
220
|
374
|
|
|
374
|
1
|
41108410
|
my ($self, $cmd, @args) = @_; my $attr = arg_list @args; |
|
374
|
|
|
|
|
4345
|
|
221
|
|
|
|
|
|
|
|
222
|
374
|
50
|
|
|
|
2390
|
$attr->{cmd } = $cmd or throw Unspecified, [ 'command' ]; |
223
|
374
|
|
|
|
|
2410
|
$attr->{log } = $self->log; |
224
|
374
|
|
|
|
|
14485
|
$attr->{rundir } = $self->config->rundir; |
225
|
374
|
|
|
|
|
17412
|
$attr->{tempdir} = $self->config->tempdir; |
226
|
|
|
|
|
|
|
|
227
|
374
|
|
|
|
|
16352
|
return Class::Usul::IPC::Cmd->new( $attr )->run_cmd; |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
sub signal_process { |
231
|
0
|
|
|
0
|
1
|
|
my ($self, @args) = @_; |
232
|
|
|
|
|
|
|
|
233
|
0
|
0
|
|
|
|
|
is_hashref $args[ 0 ] |
234
|
|
|
|
|
|
|
or return $self->run_cmd( $_signal_cmd->( $self->config->suid, @args ) ); |
235
|
|
|
|
|
|
|
|
236
|
0
|
|
|
|
|
|
my ($file, $io); my $args = $args[ 0 ]; |
|
0
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
0
|
|
0
|
|
|
|
my $sig = $args->{sig} // 'TERM'; my $pids = $args->{pids} // []; |
|
0
|
|
0
|
|
|
|
|
239
|
|
|
|
|
|
|
|
240
|
0
|
0
|
|
|
|
|
$args->{pid} and push @{ $pids }, $args->{pid}; |
|
0
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
|
242
|
0
|
0
|
0
|
|
|
|
if ($file = $args->{file} and $io = io( $file ) and $io->is_file) { |
|
|
|
0
|
|
|
|
|
243
|
0
|
|
|
|
|
|
push @{ $pids }, $io->chomp->lock->getlines; |
|
0
|
|
|
|
|
|
|
244
|
0
|
0
|
|
|
|
|
$sig eq 'TERM' and unlink $file; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
0
|
0
|
0
|
|
|
|
(defined $pids->[0] and $pids->[0] =~ m{ \d+ }mx) or throw 'Process id bad'; |
248
|
|
|
|
|
|
|
|
249
|
0
|
|
|
|
|
|
for my $mpid (@{ $pids }) { |
|
0
|
|
|
|
|
|
|
250
|
0
|
0
|
0
|
|
|
|
if (exists $args->{flag} and $args->{flag} =~ m{ one }imx) { |
251
|
0
|
|
|
|
|
|
CORE::kill $sig, $mpid; next; |
|
0
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
0
|
|
|
|
|
|
my @pids = reverse $self->child_list( $mpid ); |
255
|
|
|
|
|
|
|
|
256
|
0
|
|
|
|
|
|
CORE::kill $sig, $_ for (@pids); |
257
|
|
|
|
|
|
|
|
258
|
0
|
0
|
|
|
|
|
$args->{force} or next; |
259
|
|
|
|
|
|
|
|
260
|
0
|
|
|
|
|
|
sleep 3; @pids = reverse $self->child_list( $mpid ); |
|
0
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
|
262
|
0
|
|
|
|
|
|
CORE::kill 'KILL', $_ for (@pids); |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
0
|
|
|
|
|
|
return OK; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
sub signal_process_as_root { |
269
|
0
|
|
|
0
|
1
|
|
my ($self, @args) = @_; return $self->signal_process( arg_list @args ); |
|
0
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
1; |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
__END__ |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=pod |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=encoding utf-8 |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=head1 Name |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
Class::Usul::IPC - List / create / delete processes |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head1 Synopsis |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
use Class::Usul; |
287
|
|
|
|
|
|
|
use Class::Usul::IPC; |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
my $ipc = Class::Usul::IPC->new( builder => Class::Usul->new ); |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
$result_object = $ipc->run_cmd( [ qw( ls -l ) ] ); |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=head1 Description |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
Displays the process table and allows signals to be sent to selected |
296
|
|
|
|
|
|
|
processes |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=head1 Configuration and Environment |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
Defines these attributes; |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
=over 3 |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=item C<cache_ttys> |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
Boolean that defaults to true. Passed to L<Proc::ProcessTable> |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
=item C<config> |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
A required instance of type C<ConfigProvider> |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
=item C<log> |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
A required instance of type C<Logger> |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
=back |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
=head1 Subroutines/Methods |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
=head2 C<BUILDARGS> |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
Extracts C<config> and C<log> objects from the C<builder> attribute if it is |
323
|
|
|
|
|
|
|
supplied to the constructor |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=head2 C<child_list> |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
@pids = $self->child_list( $pid ); |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
Called with a process id for an argument this method returns a list of child |
330
|
|
|
|
|
|
|
process ids |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
=head2 C<list_pids_by_file_system> |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
@pids = $self->list_pids_by_file_system( $file_system ); |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
Returns the list of process ids produced by the C<fuser> command |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
=head2 C<popen> |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
$response = $self->popen( $cmd, @opts ); |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
Uses L<IPC::Open3> to fork a command and pipe the lines of input into |
343
|
|
|
|
|
|
|
it. Returns a C<Class::Usul::Response::IPC> object. The response |
344
|
|
|
|
|
|
|
object's C<out> method returns the B<STDOUT> from the command. Throws |
345
|
|
|
|
|
|
|
in the event of an error. See L</run_cmd> for a full list of options and |
346
|
|
|
|
|
|
|
response attributes |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
=head2 C<process_exists> |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
$bool = $self->process_exists( file => $path, pid => $pid ); |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
Tests for the existence of the specified process. Either specify a |
353
|
|
|
|
|
|
|
path to a file containing the process id or specify the id directly |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
=head2 C<process_table> |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
$res = $self->process_table( type => ..., ); |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
Returns a hash reference representing the current process table |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
=head2 C<run_cmd> |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
$response = $self->run_cmd( $cmd, $opts ); |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
Runs the given command. If C<$cmd> is a string then an implementation based on |
366
|
|
|
|
|
|
|
the L<IPC::Open3> function is used. If C<$cmd> is an array reference then an |
367
|
|
|
|
|
|
|
implementation using C<fork> and C<exec> in L<Class::Usul::IPC::Cmd> is used to |
368
|
|
|
|
|
|
|
execute the command. If the command contains pipes then an implementation based |
369
|
|
|
|
|
|
|
on L<IPC::Run> is used if it is installed. If L<IPC::Run> is not installed then |
370
|
|
|
|
|
|
|
the arrayref is joined with spaces and the C<system> implementation is |
371
|
|
|
|
|
|
|
used. The C<$opts> hash reference and the C<$response> object are described |
372
|
|
|
|
|
|
|
in L<Class::Usul::IPC::Cmd> |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
On C<MSWin32> the L</popen> method is used instead. That method does not |
375
|
|
|
|
|
|
|
support the C<async> option |
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
=head2 C<signal_process> |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
Send a signal the the selected processes. Invokes the C<suid> root wrapper |
380
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
=head2 C<signal_process_as_root> |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
$self->signal_process( [{] param => value, ... [}] ); |
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
This is called by processes running as root to send signals to |
386
|
|
|
|
|
|
|
selected processes. The passed parameters can be either a list of key |
387
|
|
|
|
|
|
|
value pairs or a hash ref. Either a single C<pid>, or an array ref |
388
|
|
|
|
|
|
|
C<pids>, or C<file> must be passwd. The C<file> parameter should be a |
389
|
|
|
|
|
|
|
path to a file containing process ids one per line. The C<sig> defaults to |
390
|
|
|
|
|
|
|
C<TERM>. If the C<flag> parameter is set to C<one> then the given signal |
391
|
|
|
|
|
|
|
will be sent once to each selected process. Otherwise each process and |
392
|
|
|
|
|
|
|
all of it's children will be sent the signal. If the C<force> |
393
|
|
|
|
|
|
|
parameter is set to true the after a grace period each process and |
394
|
|
|
|
|
|
|
it's children are sent signal C<KILL> |
395
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
=head1 Diagnostics |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
None |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
=head1 Dependencies |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
=over 3 |
403
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
=item L<Class::Usul> |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
=item L<Class::Usul::Constants> |
407
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
=item L<Class::Usul::IPC::Cmd> |
409
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
=item L<Module::Load::Conditional> |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
=item L<Proc::ProcessTable> |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
=item L<Try::Tiny> |
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
=back |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
=head1 Incompatibilities |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
There are no known incompatibilities in this module |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
=head1 Bugs and Limitations |
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
There are no known bugs in this module. |
425
|
|
|
|
|
|
|
Please report problems to the address below. |
426
|
|
|
|
|
|
|
Patches are welcome |
427
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
=head1 Author |
429
|
|
|
|
|
|
|
|
430
|
|
|
|
|
|
|
Peter Flanigan, C<< <pjfl@cpan.org> >> |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
=head1 License and Copyright |
433
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
Copyright (c) 2017 Peter Flanigan. All rights reserved |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
437
|
|
|
|
|
|
|
under the same terms as Perl itself. See L<perlartistic> |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
440
|
|
|
|
|
|
|
but WITHOUT WARRANTY; without even the implied warranty of |
441
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE |
442
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
=cut |
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
# Local Variables: |
446
|
|
|
|
|
|
|
# mode: perl |
447
|
|
|
|
|
|
|
# tab-width: 3 |
448
|
|
|
|
|
|
|
# End: |