2011-09-09 00:17:45 +00:00
|
|
|
.\" Copyright (C) 2011, Eric Biederman <ebiederm@xmission.com>
|
|
|
|
.\" Licensed under the GPLv2
|
|
|
|
.\"
|
2011-10-04 06:32:21 +00:00
|
|
|
.TH SETNS 2 2011-10-04 "Linux" "Linux Programmer's Manual"
|
2011-09-09 00:17:45 +00:00
|
|
|
.SH NAME
|
2011-10-03 06:33:39 +00:00
|
|
|
setns \- reassociate thread with a namespace
|
2011-09-09 00:17:45 +00:00
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
|
|
|
|
.B #include <sched.h>
|
|
|
|
.sp
|
|
|
|
.BI "int setns(int " fd ", int " nstype );
|
|
|
|
.fi
|
|
|
|
.SH DESCRIPTION
|
2011-09-09 00:28:35 +00:00
|
|
|
Given a file descriptor referring to a namespace,
|
2011-10-03 06:33:39 +00:00
|
|
|
reassociate the calling thread with that namespace.
|
2011-09-09 00:17:45 +00:00
|
|
|
|
2011-09-09 05:36:29 +00:00
|
|
|
The
|
|
|
|
.I fd
|
|
|
|
argument is a file descriptor referring to one of the namespace entries in a
|
|
|
|
.I /proc/[pid]/ns/
|
|
|
|
directory; see
|
|
|
|
.BR proc (5)
|
2011-10-04 06:34:28 +00:00
|
|
|
for further information on
|
2011-09-09 05:36:29 +00:00
|
|
|
.IR /proc/[pid]/ns/ .
|
2011-10-03 06:33:39 +00:00
|
|
|
The calling thread will be reassociated with the corresponding namespace,
|
2011-09-09 05:36:29 +00:00
|
|
|
subject to any constraints imposed by the
|
|
|
|
.I nstype
|
|
|
|
argument.
|
|
|
|
|
2011-09-09 00:17:45 +00:00
|
|
|
The
|
|
|
|
.I nstype
|
2011-09-09 00:28:35 +00:00
|
|
|
argument specifies which type of namespace
|
2011-10-03 06:33:39 +00:00
|
|
|
the calling thread may be reassociated with.
|
2011-09-09 00:43:49 +00:00
|
|
|
This argument can have one of the following values:
|
2011-09-09 00:17:45 +00:00
|
|
|
.TP
|
|
|
|
.BR 0
|
2011-09-09 05:36:29 +00:00
|
|
|
Allow any type of namespace to be joined.
|
2011-09-09 00:17:45 +00:00
|
|
|
.TP
|
|
|
|
.BR CLONE_NEWIPC
|
2011-09-09 05:36:29 +00:00
|
|
|
.I fd
|
|
|
|
must refer to an IPC namespace.
|
2011-09-09 00:17:45 +00:00
|
|
|
.TP
|
|
|
|
.BR CLONE_NEWNET
|
2011-09-09 05:36:29 +00:00
|
|
|
.I fd
|
|
|
|
must refer to a network namespace.
|
2011-09-09 00:17:45 +00:00
|
|
|
.TP
|
|
|
|
.BR CLONE_NEWUTS
|
2011-09-09 05:36:29 +00:00
|
|
|
.I fd
|
|
|
|
must refer to a UTS namespace.
|
2011-09-09 00:17:45 +00:00
|
|
|
.PP
|
2011-09-09 05:36:29 +00:00
|
|
|
Specifying
|
|
|
|
.I nstype
|
|
|
|
as 0 suffices if the caller knows (or does not care)
|
|
|
|
what type of namespace is referred to by
|
|
|
|
.IR fd .
|
|
|
|
Specifying a nonzero value for
|
|
|
|
.I nstype
|
|
|
|
is useful if the caller does not know what type of namespace is referred to by
|
|
|
|
.IR fd
|
|
|
|
and wants to ensure that the namespace is of a particular type.
|
|
|
|
(The caller might not know the type of the namespace referred to by
|
|
|
|
.IR fd
|
|
|
|
if the file descriptor was opened by another process and, for example,
|
|
|
|
passed to the caller via a UNIX domain socket.)
|
2011-09-09 00:17:45 +00:00
|
|
|
.SH RETURN VALUE
|
2011-09-09 05:36:29 +00:00
|
|
|
On success,
|
|
|
|
.IR setns ()
|
|
|
|
returns 0.
|
2011-09-09 00:17:45 +00:00
|
|
|
On failure, \-1 is returned and
|
|
|
|
.I errno
|
|
|
|
is set to indicate the error.
|
|
|
|
.SH ERRORS
|
|
|
|
.TP
|
|
|
|
.B EBADF
|
2011-09-09 00:28:35 +00:00
|
|
|
.I fd
|
|
|
|
is not a valid file descriptor.
|
2011-09-09 00:17:45 +00:00
|
|
|
.TP
|
|
|
|
.B EINVAL
|
2011-09-09 05:36:29 +00:00
|
|
|
.I fd
|
|
|
|
refers to a namespace whose type does not match that specified in
|
2011-10-03 06:33:39 +00:00
|
|
|
.IR nstype ,
|
|
|
|
or there is problem with reassociating the
|
|
|
|
the thread with the specified namespace.
|
2011-09-09 00:17:45 +00:00
|
|
|
.TP
|
|
|
|
.B ENOMEM
|
|
|
|
Cannot allocate sufficient memory to change the specified namespace.
|
|
|
|
.TP
|
|
|
|
.B EPERM
|
2011-10-04 06:34:28 +00:00
|
|
|
The calling thread did not have the required privilege
|
2011-09-09 00:30:51 +00:00
|
|
|
.RB ( CAP_SYS_ADMIN )
|
|
|
|
for this operation.
|
2011-09-09 00:17:45 +00:00
|
|
|
.SH VERSIONS
|
|
|
|
The
|
|
|
|
.BR setns ()
|
|
|
|
system call first appeared in Linux in kernel 3.0
|
|
|
|
.SH CONFORMING TO
|
|
|
|
The
|
|
|
|
.BR setns ()
|
|
|
|
system call is Linux-specific.
|
|
|
|
.SH NOTES
|
2011-10-03 06:33:39 +00:00
|
|
|
Not all of the attributes that can be shared when
|
|
|
|
a new thread is created using
|
2011-09-09 00:17:45 +00:00
|
|
|
.BR clone (2)
|
|
|
|
can be changed using
|
|
|
|
.BR setns ().
|
|
|
|
.SH BUGS
|
2011-09-09 00:28:35 +00:00
|
|
|
The PID namespace and the mount namespace are not currently supported.
|
|
|
|
(See the descriptions of
|
|
|
|
.BR CLONE_NEWPID
|
|
|
|
and
|
|
|
|
.BR CLONE_NEWNS
|
|
|
|
in
|
|
|
|
.BR clone (2).)
|
2011-09-09 00:17:45 +00:00
|
|
|
.SH SEE ALSO
|
|
|
|
.BR clone (2),
|
|
|
|
.BR fork (2),
|
2011-09-09 02:04:42 +00:00
|
|
|
.BR vfork (2),
|
2011-09-09 05:36:29 +00:00
|
|
|
.BR proc (5),
|
|
|
|
.BR unix (7)
|