NAME
Linux::Setns - Perl extension for switching the current process namespace to another namespace pointed by a path to the ns file descriptor.
SYNOPSIS
use Linux::setns qw(setns CLONE_ALL CLONE_NEWIPC CLONE_NEWNET CLONE_NEWUTS CLONE_NEWUSER CLONE_NEWPID);
die "setns() requires root privileges\n" if $>;
setns("/proc/PID/ns/mnt", CLONE_ALL);
# now your process is in the same namespaces(IPC,NET,UTS,PID,USER,MOUNT) as the /proc/PID/ns/mnt
# If you want to change only one of your namespaces you can use any of the bellow examples:
# Switch your current Mount namespace to the one pointed by /proc/PID/ns/mnt
setns("/proc/PID/ns/mnt", CLONE_NEWMNT);
# Switch your current IPC namespace to the one pointed by /proc/PID/ns/ipc
setns("/proc/PID/ns/ipc", CLONE_NEWIPC);
# Switch your current Network namespace to the one pointed by /proc/PID/ns/net
setns("/proc/PID/ns/net", CLONE_NEWNET);
# Switch your current UTS namespace to the one pointed by /proc/PID/ns/uts
setns("/proc/PID/ns/uts", CLONE_NEWUTS);
# Switch your current Pid namespace to the one pointed by /proc/PID/ns/pid
setns("/proc/PID/ns/pid", CLONE_NEWPID);
# Switch your current User namespace to the one pointed by /proc/PID/ns/user
setns("/proc/PID/ns/user", CLONE_NEWUSER);
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) 2016 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.10.1 or, at your option, any later version of Perl 5 you may have available.