line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Linux::Setns; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
13633
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
5
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
95
|
|
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 |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $VERSION = '1.05'; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use constant { |
31
|
1
|
|
|
|
|
258
|
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
|
1
|
|
|
1
|
|
3
|
}; |
|
1
|
|
|
|
|
2
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
require XSLoader; |
41
|
|
|
|
|
|
|
XSLoader::load('Linux::Setns', $VERSION); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Preloaded methods go here. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub setns { |
46
|
6
|
|
|
6
|
0
|
2358
|
my $ret = setns_wrapper($_[0], $_[1]); |
47
|
6
|
50
|
|
|
|
36
|
if ($ret == 0) { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
return 1; |
49
|
|
|
|
|
|
|
} elsif ($ret == 1) { |
50
|
0
|
|
|
|
|
0
|
print STDERR "Error: setns() The calling thread did not have the required privilege (CAP_SYS_ADMIN) for this operation\n"; |
51
|
|
|
|
|
|
|
} elsif ($ret == 2) { |
52
|
1
|
|
|
|
|
15
|
print STDERR "Error: setns() Unable to open file $_[0]\n"; |
53
|
|
|
|
|
|
|
} elsif ($ret == 9) { |
54
|
0
|
|
|
|
|
0
|
print STDERR "Error: setns() FD is not a valid file descriptor\n"; |
55
|
|
|
|
|
|
|
} elsif ($ret == 12) { |
56
|
0
|
|
|
|
|
0
|
print STDERR "Error: setns() Cannot allocate sufficient memory to change the specified namespace\n"; |
57
|
|
|
|
|
|
|
} elsif ($ret == 22) { |
58
|
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"; |
59
|
|
|
|
|
|
|
} |
60
|
6
|
|
|
|
|
19
|
return 0; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
__END__ |