1 | =head1 NAME |
1 | =head1 NAME |
2 | |
2 | |
3 | Linux::Clone - an interface to the linux clone(2) and unshare(2) syscalls |
3 | Linux::Clone - an interface to the linux clone, unshare, setns, pivot_root and kcmp syscalls |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use Linux::Clone; |
7 | use Linux::Clone; |
8 | |
8 | |
9 | =head1 DESCRIPTION |
9 | =head1 DESCRIPTION |
10 | |
10 | |
11 | This module exposes the linux clone(2) and unshare(2) syscalls to |
11 | This module exposes the linux clone(2), unshare(2) and related syscalls to |
12 | Perl. |
12 | Perl. |
13 | |
13 | |
14 | =over 4 |
14 | =over 4 |
15 | |
15 | |
16 | =item $retval = unshare $flags |
16 | =item $retval = unshare $flags |
… | |
… | |
24 | Linux::Clone::NEWNS (in unshare, implies FS) |
24 | Linux::Clone::NEWNS (in unshare, implies FS) |
25 | Linux::Clone::VM (in unshare, implies SIGHAND) |
25 | Linux::Clone::VM (in unshare, implies SIGHAND) |
26 | Linux::Clone::THREAD (in unshare, implies VM, SIGHAND) |
26 | Linux::Clone::THREAD (in unshare, implies VM, SIGHAND) |
27 | Linux::Clone::SIGHAND |
27 | Linux::Clone::SIGHAND |
28 | Linux::Clone::SYSVSEM |
28 | Linux::Clone::SYSVSEM |
|
|
29 | Linux::Clone::NEWUSER (in unshare, implies CLONE_THREAD) |
|
|
30 | Linux::Clone::NEWPID |
29 | Linux::Clone::NEWUTS |
31 | Linux::Clone::NEWUTS |
30 | Linux::Clone::NEWIPC |
32 | Linux::Clone::NEWIPC |
31 | Linux::Clone::NEWNET |
33 | Linux::Clone::NEWNET |
|
|
34 | Linux::Clone::NEWCGROUP |
32 | |
35 | |
33 | Example: unshare the network namespace and prove that by calling ifconfig, |
36 | Example: unshare the network namespace and prove that by calling ifconfig, |
34 | showing only an unconfigured lo interface. |
37 | showing only an unconfigured lo interface. |
35 | |
38 | |
36 | Linux::Clone::unshare Linux::Clone::NEWNET |
39 | Linux::Clone::unshare Linux::Clone::NEWNET |
… | |
… | |
122 | Linux::Clone::PARENT_SETTID (not yet implemented) |
125 | Linux::Clone::PARENT_SETTID (not yet implemented) |
123 | Linux::Clone::CHILD_SETTID (not yet implemented) |
126 | Linux::Clone::CHILD_SETTID (not yet implemented) |
124 | Linux::Clone::CHILD_CLEARTID (not yet implemented) |
127 | Linux::Clone::CHILD_CLEARTID (not yet implemented) |
125 | Linux::Clone::DETACHED |
128 | Linux::Clone::DETACHED |
126 | Linux::Clone::UNTRACED |
129 | Linux::Clone::UNTRACED |
127 | Linux::Clone::NEWUSER |
|
|
128 | Linux::Clone::NEWPID |
|
|
129 | Linux::Clone::IO |
130 | Linux::Clone::IO |
130 | |
131 | |
131 | Note that for practical reasons you basically must not use |
132 | Note that for practical reasons you basically must not use |
132 | C<Linux::Clone::VM> or C<Linux::Clone::VFORK>, as perl is unlikely to cope |
133 | C<Linux::Clone::VM> or C<Linux::Clone::VFORK>, as perl is unlikely to cope |
133 | with that. |
134 | with that. |
… | |
… | |
137 | Example: do a fork-like clone, sharing nothing, slightly confusing perl |
138 | Example: do a fork-like clone, sharing nothing, slightly confusing perl |
138 | and your libc, and exit immediately. |
139 | and your libc, and exit immediately. |
139 | |
140 | |
140 | my $pid = Linux::Clone::clone sub { warn "in child"; 77 }, 0, POSIX::SIGCHLD; |
141 | my $pid = Linux::Clone::clone sub { warn "in child"; 77 }, 0, POSIX::SIGCHLD; |
141 | |
142 | |
|
|
143 | =item Linux::Clone::setns $fh_or_fd[, $nstype] |
|
|
144 | |
|
|
145 | Calls setns(2) on the file descriptor (or file handle) C<$fh_or_fd>. If |
|
|
146 | C<$nstype> is missing, then C<0> is used. |
|
|
147 | |
|
|
148 | The argument C<$nstype> can be C<0>, C<Linux::Clone::NEWIPC>, |
|
|
149 | C<Linux::Clone::NEWNET>, C<Linux::Clone::NEUTS>, C<Linux::Clone::NEWCGROUP>, |
|
|
150 | C<Linux::Clone::NEWNS>, C<Linux::Clone::NEWPID> or C<Linux::Clone::NEWUSER>. |
|
|
151 | |
|
|
152 | =item Linux::Clone::pivot_root $new_root, $old_root |
|
|
153 | |
|
|
154 | Calls pivot_root(2) - refer to its manpage for details. |
|
|
155 | |
|
|
156 | =item Linux::Clone::kcmp $pid1, $pid2, $type[, $idx1, $idx2] |
|
|
157 | |
|
|
158 | Calls kcmp(2) - refer to its manpage for details on operations. |
|
|
159 | |
|
|
160 | The following C<$type> constants are available if the kcmp syscall number |
|
|
161 | was available during compilation: |
|
|
162 | |
|
|
163 | C<Linux::Clone::KCMP_FILE>, C<Linux::Clone::KCMP_VM>, C<Linux::Clone::KCMP_FILES>, |
|
|
164 | C<Linux::Clone::KCMP_FS>, C<Linux::Clone::KCMP_SIGHAND>, C<Linux::Clone::KCMP_IO> and |
|
|
165 | C<Linux::Clone::KCMP_SYSVSEM>. |
|
|
166 | |
|
|
167 | |
142 | =back |
168 | =back |
143 | |
169 | |
144 | =cut |
170 | =cut |
145 | |
171 | |
146 | package Linux::Clone; |
172 | package Linux::Clone; |
147 | |
173 | |
148 | # use common::sense; |
174 | # use common::sense; |
149 | |
175 | |
150 | BEGIN { |
176 | BEGIN { |
151 | our $VERSION = '0.01'; |
177 | our $VERSION = '1.2'; |
152 | |
178 | |
153 | require XSLoader; |
179 | require XSLoader; |
154 | XSLoader::load (__PACKAGE__, $VERSION); |
180 | XSLoader::load (__PACKAGE__, $VERSION); |
155 | } |
181 | } |
156 | |
182 | |