NAME
Linux::Setns - Perl extension for switching the current prcoess namespace to another namespace pointed by a file descriptor.
SYNOPSIS
use Linux::Unshare qw(unshare :clone);
die "setns() requires root privileges\n" if $<;
open my $FD, '<', "/proc/PID/ns/mnt" or die "setns(): unable to open FD\n";
setns($FD, CLONE_ALL);
# now your process is in the same namespace as the $FD you have supplied
# in this case, you have to previously know what is the type of namespace of that $FD
setns($FD, CLONE_NEWIPC);
# Switch your current IPC namespace to the one pointed by $FD
setns($FD, CLONE_NEWNET);
# Switch your current Network namespace to the one pointed by $FD
setns($FD, CLONE_NEWUTC);
# Switch your current UTS namespace to the one pointed by $FD
DESCRIPTION
This trivial module provides interface to the Linux setns system call. It also provides the CLONE_* constants that are used to specify which kind of namespace you are entering. Also a new CLONE_ALL constat is provided so you can join/switch to any type of namespace.
The setns system call allows a process to 'join/switch' one of its namespaces to namespace pointed by a file descriptor(usually located in /proc/PID/ns/{ipc,mnt,net,pid,user,uts}).
Note: keep in mind that using CLONE_NEWIPC, CLONE_NEWNET or CLONE_NEWUTS will fail if the FD is not of that type.
RETRUN VALUE 1 on success 0 on failure
EXPORT
setns - the subroutine
CLONE_ALL - flag that tells that the FD can be of any namespace type
CLONE_NEWIPC - when this flag is used the FD must be from a IPC namespace
CLONE_NEWNET - when this flag is used the FD must be from a Network namespace
CLONE_NEWUTS - when this flag is used the FD must be from a UTS namespace
SEE ALSO
setns(s) Linux man page.
AUTHOR
Marian HackMan Marinov, <hackman@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2014 by Marian HackMan Marinov
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.18.1 or, at your option, any later version of Perl 5 you may have available.