line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Linux::Setns; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23360
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
47
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
136
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
12
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
13
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# This allows declaration use Linux::Setns ':all'; |
16
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
17
|
|
|
|
|
|
|
# will save memory. |
18
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
) ] ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @EXPORT = qw( |
25
|
|
|
|
|
|
|
setns CLONE_ALL CLONE_NEWNS CLONE_NEWIPC CLONE_NEWNET CLONE_NEWUTS CLONE_NEWPID CLONE_NEWUSER CLONE_NEWCGROUP |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $VERSION = '2.00'; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use constant { |
31
|
1
|
|
|
|
|
302
|
CLONE_ALL => 0, |
32
|
|
|
|
|
|
|
CLONE_NEWNS => 0x00020000, |
33
|
|
|
|
|
|
|
CLONE_NEWIPC => 0x08000000, |
34
|
|
|
|
|
|
|
CLONE_NEWNET => 0x40000000, |
35
|
|
|
|
|
|
|
CLONE_NEWUTS => 0x04000000, |
36
|
|
|
|
|
|
|
CLONE_NEWPID => 0x20000000, |
37
|
|
|
|
|
|
|
CLONE_NEWUSER => 0x10000000, |
38
|
|
|
|
|
|
|
CLONE_NEWCGROUP => 0x02000000 |
39
|
1
|
|
|
1
|
|
5
|
}; |
|
1
|
|
|
|
|
2
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
require XSLoader; |
42
|
|
|
|
|
|
|
XSLoader::load('Linux::Setns', $VERSION); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Preloaded methods go here. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub setns { |
47
|
6
|
|
|
6
|
0
|
3616
|
my $ret = setns_wrapper($_[0], $_[1]); |
48
|
6
|
50
|
|
|
|
52
|
if ($ret == 0) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
49
|
0
|
|
|
|
|
0
|
return 1; |
50
|
|
|
|
|
|
|
} elsif ($ret == 1) { |
51
|
0
|
|
|
|
|
0
|
print STDERR "Error: setns() The calling thread did not have the required privilege (CAP_SYS_ADMIN) for this operation\n"; |
52
|
|
|
|
|
|
|
} elsif ($ret == 2) { |
53
|
1
|
|
|
|
|
12
|
print STDERR "Error: setns() Unable to open file $_[0]\n"; |
54
|
|
|
|
|
|
|
} elsif ($ret == 9) { |
55
|
0
|
|
|
|
|
0
|
print STDERR "Error: setns() FD is not a valid file descriptor\n"; |
56
|
|
|
|
|
|
|
} elsif ($ret == 12) { |
57
|
0
|
|
|
|
|
0
|
print STDERR "Error: setns() Cannot allocate sufficient memory to change the specified namespace\n"; |
58
|
|
|
|
|
|
|
} elsif ($ret == 22) { |
59
|
0
|
|
|
|
|
0
|
print STDERR "Error: setns() FD refers to a namespace whose type does not match that specified in nstype, or there is problem with reassociating the the thread with the specified namespace\n"; |
60
|
|
|
|
|
|
|
} |
61
|
6
|
|
|
|
|
27
|
return 0; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
__END__ |