line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ubic::Daemon::OS::POSIX; |
2
|
|
|
|
|
|
|
$Ubic::Daemon::OS::POSIX::VERSION = '1.60'; |
3
|
1
|
|
|
1
|
|
2818
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
47
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: POSIX-compatible daemonize helpers |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Params::Validate qw(:all); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
127
|
|
9
|
1
|
|
|
1
|
|
8
|
use POSIX qw(:unistd_h); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
287
|
use parent qw(Ubic::Daemon::OS); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub pid2guid { |
14
|
0
|
|
|
0
|
1
|
|
my ($self, $pid) = validate_pos(@_, 1, { type => SCALAR, regex => qr/^\d+$/ }); |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
return unless $self->pid_exists($pid); |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
return 'NULL'; # no guid on mac os x yet |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub pid2cmd { |
22
|
0
|
|
|
0
|
1
|
|
my ($self, $pid) = validate_pos(@_, 1, { type => SCALAR, regex => qr/^\d+$/ }); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# see POSIX specification - http://pubs.opengroup.org/onlinepubs/009696799/utilities/ps.html |
25
|
0
|
|
|
|
|
|
my $result = qx(ps -p $pid -o pid,comm 2>/dev/null); |
26
|
0
|
|
|
|
|
|
$result =~ s/^.*\n//; # drop first line |
27
|
0
|
|
|
|
|
|
my ($ps_pid, $ps_command) = $result =~ /^\s*(\d+)\s+(.*)$/; |
28
|
0
|
0
|
|
|
|
|
unless ($ps_pid) { |
29
|
0
|
|
|
|
|
|
warn "Daemon $pid not found"; |
30
|
0
|
|
|
|
|
|
return 'unknown'; |
31
|
|
|
|
|
|
|
} |
32
|
0
|
0
|
|
|
|
|
unless ($ps_pid == $pid) { |
33
|
0
|
|
|
|
|
|
die "Internal error, expected pid $pid, got pid $ps_pid"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return $ps_command; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub close_all_fh { |
40
|
0
|
|
|
0
|
1
|
|
my ($self, @except) = @_; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
for my $fd (0 .. POSIX::sysconf(POSIX::_SC_OPEN_MAX)) { |
43
|
0
|
0
|
|
|
|
|
next if grep { $_ == $fd } @except; |
|
0
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
POSIX::close($fd); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub pid_exists { |
49
|
0
|
|
|
0
|
1
|
|
my ($self, $pid) = validate_pos(@_, 1, { type => SCALAR, regex => qr/^\d+$/ }); |
50
|
0
|
|
|
|
|
|
my $result = qx(ps -p $pid -o pid 2>/dev/null); |
51
|
0
|
0
|
|
|
|
|
if ($result =~ /\d/) { |
52
|
0
|
|
|
|
|
|
return 1; |
53
|
|
|
|
|
|
|
} |
54
|
0
|
|
|
|
|
|
return; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |