line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pcore::Util::PM; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
41
|
use Pcore -export, [qw[is_superuser run_proc run_rpc connect_rpc]]; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
44
|
|
4
|
5
|
|
|
5
|
|
2090
|
use POSIX qw[]; |
|
5
|
|
|
|
|
32433
|
|
|
5
|
|
|
|
|
4763
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub change_priv { |
7
|
5
|
|
|
5
|
0
|
29
|
my %args = ( |
8
|
|
|
|
|
|
|
gid => undef, |
9
|
|
|
|
|
|
|
uid => undef, |
10
|
|
|
|
|
|
|
@_, |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
5
|
50
|
|
|
|
26
|
if ( !$MSWIN ) { |
14
|
5
|
50
|
|
|
|
20
|
if ( defined $args{gid} ) { |
15
|
0
|
0
|
|
|
|
0
|
my $gid = $args{gid} =~ /\A\d+\z/sm ? $args{gid} : getgrnam $args{gid}; |
16
|
|
|
|
|
|
|
|
17
|
0
|
0
|
|
|
|
0
|
croak qq[Can't find gid: "$args{gid}"] if !defined $gid; |
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
0
|
POSIX::setgid($gid) or die qq[Can't set GID to "$args{gid}". $!]; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
5
|
50
|
|
|
|
21
|
if ( defined $args{uid} ) { |
23
|
0
|
0
|
|
|
|
0
|
my $uid = $args{uid} =~ /\A\d+\z/sm ? $args{uid} : getpwnam $args{uid}; |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
0
|
croak qq[Can't find uid "$args{uid}"] if !defined $uid; |
26
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
0
|
POSIX::setuid($uid) or die qq[Can't set UID to "$args{uid}". $!]; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
5
|
|
|
|
|
19
|
return; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub daemonize { |
35
|
0
|
|
|
0
|
0
|
|
state $daemonized = 0; |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
return 0 if $daemonized; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$daemonized++; |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
if ( !$MSWIN ) { |
42
|
0
|
0
|
|
|
|
|
fork && exit 0; ## no critic qw[InputOutput::RequireCheckedSyscalls] |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
open STDIN, '+<', '/dev/null' or die; |
45
|
0
|
0
|
|
|
|
|
open STDOUT, '>&STDIN' or die; |
46
|
0
|
0
|
|
|
|
|
open STDERR, '>&STDIN' or die; |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
open $STDOUT_UTF8, '>&STDIN' or die; ## no critic qw[InputOutput::RequireBriefOpen] |
49
|
0
|
0
|
|
|
|
|
open $STDERR_UTF8, '>&STDIN' or die; ## no critic qw[InputOutput::RequireBriefOpen] |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
POSIX::setsid() or die qq[Can't set sid: $!]; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return 1; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
return 0; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub is_superuser { |
60
|
0
|
0
|
|
0
|
0
|
|
if ($MSWIN) { |
61
|
0
|
|
|
|
|
|
return Win32::IsAdminUser(); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
0
|
0
|
|
|
|
|
return $> == 0 ? 1 : 0; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
0
|
0
|
|
sub run_proc (@) { |
|
0
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
state $init = !!require Pcore::Util::PM::Proc; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return Pcore::Util::PM::Proc->new(@_); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
0
|
0
|
|
sub run_rpc ( $class, @ ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
state $init = !!require Pcore::RPC; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return Pcore::RPC->run_rpc(@_); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
0
|
0
|
|
sub connect_rpc ( $connect, %args ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
state $init = !!require Pcore::RPC; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return Pcore::RPC->connect_rpc( %args, connect => $connect ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
__END__ |
88
|
|
|
|
|
|
|
=pod |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=encoding utf8 |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 NAME |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Pcore::Util::PM - pcore processs management util functions |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 SYNOPSIS |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 DESCRIPTION |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |