Blame man2/unshare.2

Packit 7cfc04
.\" Copyright (C) 2006, Janak Desai <janak@us.ibm.com>
Packit 7cfc04
.\" and Copyright (C) 2006, 2012 Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
Packit 7cfc04
.\" Licensed under the GPL
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" Patch Justification:
Packit 7cfc04
.\" unshare system call is needed to implement, using PAM,
Packit 7cfc04
.\" per-security_context and/or per-user namespace to provide
Packit 7cfc04
.\" polyinstantiated directories. Using unshare and bind mounts, a
Packit 7cfc04
.\" PAM module can create private namespace with appropriate
Packit 7cfc04
.\" directories(based on user's security context) bind mounted on
Packit 7cfc04
.\" public directories such as /tmp, thus providing an instance of
Packit 7cfc04
.\" /tmp that is based on user's security context. Without the
Packit 7cfc04
.\" unshare system call, namespace separation can only be achieved
Packit 7cfc04
.\" by clone, which would require porting and maintaining all commands
Packit 7cfc04
.\" such as login, and su, that establish a user session.
Packit 7cfc04
.\"
Packit 7cfc04
.TH UNSHARE 2 2018-02-02 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
unshare \- disassociate parts of the process execution context
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #define _GNU_SOURCE
Packit 7cfc04
.B #include <sched.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int unshare(int " flags );
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.BR unshare ()
Packit 7cfc04
allows a process (or thread) to disassociate parts of its execution
Packit 7cfc04
context that are currently being shared with other processes (or threads).
Packit 7cfc04
Part of the execution context, such as the mount namespace, is shared
Packit 7cfc04
implicitly when a new process is created using
Packit 7cfc04
.BR fork (2)
Packit 7cfc04
or
Packit 7cfc04
.BR vfork (2),
Packit 7cfc04
while other parts, such as virtual memory, may be
Packit 7cfc04
shared by explicit request when creating a process or thread using
Packit 7cfc04
.BR clone (2).
Packit 7cfc04
.PP
Packit 7cfc04
The main use of
Packit 7cfc04
.BR unshare ()
Packit 7cfc04
is to allow a process to control its
Packit 7cfc04
shared execution context without creating a new process.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I flags
Packit 7cfc04
argument is a bit mask that specifies which parts of
Packit 7cfc04
the execution context should be unshared.
Packit 7cfc04
This argument is specified by ORing together zero or more
Packit 7cfc04
of the following constants:
Packit 7cfc04
.TP
Packit 7cfc04
.B CLONE_FILES
Packit 7cfc04
Reverse the effect of the
Packit 7cfc04
.BR clone (2)
Packit 7cfc04
.B CLONE_FILES
Packit 7cfc04
flag.
Packit 7cfc04
Unshare the file descriptor table, so that the calling process
Packit 7cfc04
no longer shares its file descriptors with any other process.
Packit 7cfc04
.TP
Packit 7cfc04
.B CLONE_FS
Packit 7cfc04
Reverse the effect of the
Packit 7cfc04
.BR clone (2)
Packit 7cfc04
.B CLONE_FS
Packit 7cfc04
flag.
Packit 7cfc04
Unshare filesystem attributes, so that the calling process
Packit 7cfc04
no longer shares its root directory
Packit 7cfc04
.RB ( chroot (2)),
Packit 7cfc04
current directory
Packit 7cfc04
.RB ( chdir (2)),
Packit 7cfc04
or umask
Packit 7cfc04
.RB ( umask (2))
Packit 7cfc04
attributes with any other process.
Packit 7cfc04
.TP
Packit 7cfc04
.BR CLONE_NEWCGROUP " (since Linux 4.6)"
Packit 7cfc04
This flag has the same effect as the
Packit 7cfc04
.BR clone (2)
Packit 7cfc04
.B CLONE_NEWCGROUP
Packit 7cfc04
flag.
Packit 7cfc04
Unshare the cgroup namespace.
Packit 7cfc04
Use of
Packit 7cfc04
.BR CLONE_NEWCGROUP
Packit 7cfc04
requires the
Packit 7cfc04
.BR CAP_SYS_ADMIN
Packit 7cfc04
capability.
Packit 7cfc04
.TP
Packit 7cfc04
.BR CLONE_NEWIPC " (since Linux 2.6.19)"
Packit 7cfc04
This flag has the same effect as the
Packit 7cfc04
.BR clone (2)
Packit 7cfc04
.B CLONE_NEWIPC
Packit 7cfc04
flag.
Packit 7cfc04
Unshare the IPC namespace,
Packit 7cfc04
so that the calling process has a private copy of the
Packit 7cfc04
IPC namespace which is not shared with any other process.
Packit 7cfc04
Specifying this flag automatically implies
Packit 7cfc04
.BR CLONE_SYSVSEM
Packit 7cfc04
as well.
Packit 7cfc04
Use of
Packit 7cfc04
.BR CLONE_NEWIPC
Packit 7cfc04
requires the
Packit 7cfc04
.BR CAP_SYS_ADMIN
Packit 7cfc04
capability.
Packit 7cfc04
.TP
Packit 7cfc04
.BR CLONE_NEWNET " (since Linux 2.6.24)"
Packit 7cfc04
This flag has the same effect as the
Packit 7cfc04
.BR clone (2)
Packit 7cfc04
.B CLONE_NEWNET
Packit 7cfc04
flag.
Packit 7cfc04
Unshare the network namespace,
Packit 7cfc04
so that the calling process is moved into a
Packit 7cfc04
new network namespace which is not shared
Packit 7cfc04
with any previously existing process.
Packit 7cfc04
Use of
Packit 7cfc04
.BR CLONE_NEWNET
Packit 7cfc04
requires the
Packit 7cfc04
.BR CAP_SYS_ADMIN
Packit 7cfc04
capability.
Packit 7cfc04
.TP
Packit 7cfc04
.B CLONE_NEWNS
Packit 7cfc04
.\" These flag name are inconsistent:
Packit 7cfc04
.\" CLONE_NEWNS does the same thing in clone(), but CLONE_VM,
Packit 7cfc04
.\" CLONE_FS, and CLONE_FILES reverse the action of the clone()
Packit 7cfc04
.\" flags of the same name.
Packit 7cfc04
This flag has the same effect as the
Packit 7cfc04
.BR clone (2)
Packit 7cfc04
.B CLONE_NEWNS
Packit 7cfc04
flag.
Packit 7cfc04
Unshare the mount namespace,
Packit 7cfc04
so that the calling process has a private copy of
Packit 7cfc04
its namespace which is not shared with any other process.
Packit 7cfc04
Specifying this flag automatically implies
Packit 7cfc04
.B CLONE_FS
Packit 7cfc04
as well.
Packit 7cfc04
Use of
Packit 7cfc04
.BR CLONE_NEWNS
Packit 7cfc04
requires the
Packit 7cfc04
.BR CAP_SYS_ADMIN
Packit 7cfc04
capability.
Packit 7cfc04
For further information, see
Packit 7cfc04
.BR mount_namespaces (7).
Packit 7cfc04
.TP
Packit 7cfc04
.BR CLONE_NEWPID " (since Linux 3.8)"
Packit 7cfc04
This flag has the same effect as the
Packit 7cfc04
.BR clone (2)
Packit 7cfc04
.B CLONE_NEWPID
Packit 7cfc04
flag.
Packit 7cfc04
Unshare the PID namespace,
Packit 7cfc04
so that the calling process has a new PID namespace for its children
Packit 7cfc04
which is not shared with any previously existing process.
Packit 7cfc04
The calling process is
Packit 7cfc04
.I not
Packit 7cfc04
moved into the new namespace.
Packit 7cfc04
The first child created by the calling process will have
Packit 7cfc04
the process ID 1 and will assume the role of
Packit 7cfc04
.BR init (1)
Packit 7cfc04
in the new namespace.
Packit 7cfc04
.BR CLONE_NEWPID
Packit 7cfc04
automatically implies
Packit 7cfc04
.BR CLONE_THREAD
Packit 7cfc04
as well.
Packit 7cfc04
Use of
Packit 7cfc04
.BR CLONE_NEWPID
Packit 7cfc04
requires the
Packit 7cfc04
.BR CAP_SYS_ADMIN
Packit 7cfc04
capability.
Packit 7cfc04
For further information, see
Packit 7cfc04
.BR pid_namespaces (7).
Packit 7cfc04
.TP
Packit 7cfc04
.BR CLONE_NEWUSER " (since Linux 3.8)"
Packit 7cfc04
This flag has the same effect as the
Packit 7cfc04
.BR clone (2)
Packit 7cfc04
.B CLONE_NEWUSER
Packit 7cfc04
flag.
Packit 7cfc04
Unshare the user namespace,
Packit 7cfc04
so that the calling process is moved into a new user namespace
Packit 7cfc04
which is not shared with any previously existing process.
Packit 7cfc04
As with the child process created by
Packit 7cfc04
.BR clone (2)
Packit 7cfc04
with the
Packit 7cfc04
.B CLONE_NEWUSER
Packit 7cfc04
flag, the caller obtains a full set of capabilities in the new namespace.
Packit 7cfc04
.IP
Packit 7cfc04
.BR CLONE_NEWUSER
Packit 7cfc04
requires that the calling process is not threaded; specifying
Packit 7cfc04
.BR CLONE_NEWUSER
Packit 7cfc04
automatically implies
Packit 7cfc04
.BR CLONE_THREAD .
Packit 7cfc04
Since Linux 3.9,
Packit 7cfc04
.\" commit e66eded8309ebf679d3d3c1f5820d1f2ca332c71
Packit 7cfc04
.\" https://lwn.net/Articles/543273/
Packit 7cfc04
.BR CLONE_NEWUSER
Packit 7cfc04
also automatically implies
Packit 7cfc04
.BR CLONE_FS .
Packit 7cfc04
.BR CLONE_NEWUSER
Packit 7cfc04
requires that the user ID and group ID
Packit 7cfc04
of the calling process are mapped to user IDs and group IDs in the
Packit 7cfc04
user namespace of the calling process at the time of the call.
Packit 7cfc04
.IP
Packit 7cfc04
For further information on user namespaces, see
Packit 7cfc04
.BR user_namespaces (7).
Packit 7cfc04
.TP
Packit 7cfc04
.BR CLONE_NEWUTS " (since Linux 2.6.19)"
Packit 7cfc04
This flag has the same effect as the
Packit 7cfc04
.BR clone (2)
Packit 7cfc04
.B CLONE_NEWUTS
Packit 7cfc04
flag.
Packit 7cfc04
Unshare the UTS IPC namespace,
Packit 7cfc04
so that the calling process has a private copy of the
Packit 7cfc04
UTS namespace which is not shared with any other process.
Packit 7cfc04
Use of
Packit 7cfc04
.BR CLONE_NEWUTS
Packit 7cfc04
requires the
Packit 7cfc04
.BR CAP_SYS_ADMIN
Packit 7cfc04
capability.
Packit 7cfc04
.TP
Packit 7cfc04
.BR CLONE_SYSVSEM " (since Linux 2.6.26)
Packit 7cfc04
.\" commit 9edff4ab1f8d82675277a04e359d0ed8bf14a7b7
Packit 7cfc04
This flag reverses the effect of the
Packit 7cfc04
.BR clone (2)
Packit 7cfc04
.B CLONE_SYSVSEM
Packit 7cfc04
flag.
Packit 7cfc04
Unshare System\ V semaphore adjustment
Packit 7cfc04
.RI ( semadj )
Packit 7cfc04
values,
Packit 7cfc04
so that the calling process has a new empty
Packit 7cfc04
.I semadj
Packit 7cfc04
list that is not shared with any other process.
Packit 7cfc04
If this is the last process that has a reference to the process's current
Packit 7cfc04
.I semadj
Packit 7cfc04
list, then the adjustments in that list are applied
Packit 7cfc04
to the corresponding semaphores, as described in
Packit 7cfc04
.BR semop (2).
Packit 7cfc04
.\" CLONE_NEWNS If CLONE_SIGHAND is set and signals are also being shared
Packit 7cfc04
.\" (i.e., current->signal->count > 1), force CLONE_THREAD.
Packit 7cfc04
.PP
Packit 7cfc04
In addition,
Packit 7cfc04
.BR CLONE_THREAD ,
Packit 7cfc04
.BR CLONE_SIGHAND ,
Packit 7cfc04
and
Packit 7cfc04
.BR CLONE_VM
Packit 7cfc04
can be specified in
Packit 7cfc04
.I flags
Packit 7cfc04
if the caller is single threaded (i.e., it is not sharing
Packit 7cfc04
its address space with another process or thread).
Packit 7cfc04
In this case, these flags have no effect.
Packit 7cfc04
(Note also that specifying
Packit 7cfc04
.BR CLONE_THREAD
Packit 7cfc04
automatically implies
Packit 7cfc04
.BR CLONE_VM ,
Packit 7cfc04
and specifying
Packit 7cfc04
.BR CLONE_VM
Packit 7cfc04
automatically implies
Packit 7cfc04
.BR CLONE_SIGHAND .)
Packit 7cfc04
.\" As at 3.9, the following forced implications also apply,
Packit 7cfc04
.\" although the relevant flags are not yet implemented.
Packit 7cfc04
.\" If CLONE_THREAD is set force CLONE_VM.
Packit 7cfc04
.\" If CLONE_VM is set, force CLONE_SIGHAND.
Packit 7cfc04
.\"
Packit 7cfc04
If the process is multithreaded, then
Packit 7cfc04
the use of these flags results in an error.
Packit 7cfc04
.\" See kernel/fork.c::check_unshare_flags()
Packit 7cfc04
.PP
Packit 7cfc04
If
Packit 7cfc04
.I flags
Packit 7cfc04
is specified as zero, then
Packit 7cfc04
.BR unshare ()
Packit 7cfc04
is a no-op;
Packit 7cfc04
no changes are made to the calling process's execution context.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
On success, zero returned.
Packit 7cfc04
On failure, \-1 is returned and
Packit 7cfc04
.I errno
Packit 7cfc04
is set to indicate the error.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
An invalid bit was specified in
Packit 7cfc04
.IR flags .
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
.BR CLONE_THREAD ,
Packit 7cfc04
.BR CLONE_SIGHAND ,
Packit 7cfc04
or
Packit 7cfc04
.BR CLONE_VM
Packit 7cfc04
was specified in
Packit 7cfc04
.IR flags ,
Packit 7cfc04
and the caller is multithreaded.
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOMEM
Packit 7cfc04
Cannot allocate sufficient memory to copy parts of caller's
Packit 7cfc04
context that need to be unshared.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENOSPC " (since Linux 3.7)"
Packit 7cfc04
.\" commit f2302505775fd13ba93f034206f1e2a587017929
Packit 7cfc04
.B CLONE_NEWPID
Packit 7cfc04
was specified in flags,
Packit 7cfc04
but the limit on the nesting depth of PID namespaces
Packit 7cfc04
would have been exceeded; see
Packit 7cfc04
.BR pid_namespaces (7).
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENOSPC " (since Linux 4.9; beforehand " EUSERS )
Packit 7cfc04
.B CLONE_NEWUSER
Packit 7cfc04
was specified in
Packit 7cfc04
.IR flags ,
Packit 7cfc04
and the call would cause the limit on the number of
Packit 7cfc04
nested user namespaces to be exceeded.
Packit 7cfc04
See
Packit 7cfc04
.BR user_namespaces (7).
Packit 7cfc04
.IP
Packit 7cfc04
From Linux 3.11 to Linux 4.8, the error diagnosed in this case was
Packit 7cfc04
.BR EUSERS .
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENOSPC " (since Linux 4.9)"
Packit 7cfc04
One of the values in
Packit 7cfc04
.I flags
Packit 7cfc04
specified the creation of a new user namespace,
Packit 7cfc04
but doing so would have caused the limit defined by the corresponding file in
Packit 7cfc04
.IR /proc/sys/user
Packit 7cfc04
to be exceeded.
Packit 7cfc04
For further details, see
Packit 7cfc04
.BR namespaces (7).
Packit 7cfc04
.TP
Packit 7cfc04
.B EPERM
Packit 7cfc04
The calling process did not have the required privileges for this operation.
Packit 7cfc04
.TP
Packit 7cfc04
.B EPERM
Packit 7cfc04
.BR CLONE_NEWUSER
Packit 7cfc04
was specified in
Packit 7cfc04
.IR flags ,
Packit 7cfc04
but either the effective user ID or the effective group ID of the caller
Packit 7cfc04
does not have a mapping in the parent namespace (see
Packit 7cfc04
.BR user_namespaces (7)).
Packit 7cfc04
.TP
Packit 7cfc04
.BR EPERM " (since Linux 3.9)"
Packit 7cfc04
.\" commit 3151527ee007b73a0ebd296010f1c0454a919c7d
Packit 7cfc04
.B CLONE_NEWUSER
Packit 7cfc04
was specified in
Packit 7cfc04
.I flags
Packit 7cfc04
and the caller is in a chroot environment
Packit 7cfc04
.\" FIXME What is the rationale for this restriction?
Packit 7cfc04
(i.e., the caller's root directory does not match the root directory
Packit 7cfc04
of the mount namespace in which it resides).
Packit 7cfc04
.TP
Packit 7cfc04
.BR EUSERS " (from Linux 3.11 to Linux 4.8)"
Packit 7cfc04
.B CLONE_NEWUSER
Packit 7cfc04
was specified in
Packit 7cfc04
.IR flags ,
Packit 7cfc04
and the limit on the number of nested user namespaces would be exceeded.
Packit 7cfc04
See the discussion of the
Packit 7cfc04
.BR ENOSPC
Packit 7cfc04
error above.
Packit 7cfc04
.SH VERSIONS
Packit 7cfc04
The
Packit 7cfc04
.BR unshare ()
Packit 7cfc04
system call was added to Linux in kernel 2.6.16.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
The
Packit 7cfc04
.BR unshare ()
Packit 7cfc04
system call is Linux-specific.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
Not all of the process attributes that can be shared when
Packit 7cfc04
a new process is created using
Packit 7cfc04
.BR clone (2)
Packit 7cfc04
can be unshared using
Packit 7cfc04
.BR unshare ().
Packit 7cfc04
In particular, as at kernel 3.8,
Packit 7cfc04
.\" FIXME all of the following needs to be reviewed for the current kernel
Packit 7cfc04
.BR unshare ()
Packit 7cfc04
does not implement flags that reverse the effects of
Packit 7cfc04
.BR CLONE_SIGHAND ,
Packit 7cfc04
.\" However, we can do unshare(CLONE_SIGHAND) if CLONE_SIGHAND
Packit 7cfc04
.\" was not specified when doing clone(); i.e., unsharing
Packit 7cfc04
.\" signal handlers is permitted if we are not actually
Packit 7cfc04
.\" sharing signal handlers.   mtk
Packit 7cfc04
.BR CLONE_THREAD ,
Packit 7cfc04
or
Packit 7cfc04
.BR CLONE_VM .
Packit 7cfc04
.\" However, we can do unshare(CLONE_VM) if CLONE_VM
Packit 7cfc04
.\" was not specified when doing clone(); i.e., unsharing
Packit 7cfc04
.\" virtual memory is permitted if we are not actually
Packit 7cfc04
.\" sharing virtual memory.   mtk
Packit 7cfc04
Such functionality may be added in the future, if required.
Packit 7cfc04
.\"
Packit 7cfc04
.\"9) Future Work
Packit 7cfc04
.\"--------------
Packit 7cfc04
.\"The current implementation of unshare does not allow unsharing of
Packit 7cfc04
.\"signals and signal handlers. Signals are complex to begin with and
Packit 7cfc04
.\"to unshare signals and/or signal handlers of a currently running
Packit 7cfc04
.\"process is even more complex. If in the future there is a specific
Packit 7cfc04
.\"need to allow unsharing of signals and/or signal handlers, it can
Packit 7cfc04
.\"be incrementally added to unshare without affecting legacy
Packit 7cfc04
.\"applications using unshare.
Packit 7cfc04
.\"
Packit 7cfc04
.SH EXAMPLE
Packit 7cfc04
The program below provides a simple implementation of the
Packit 7cfc04
.BR unshare (1)
Packit 7cfc04
command, which unshares one or more namespaces and executes the
Packit 7cfc04
command supplied in its command-line arguments.
Packit 7cfc04
Here's an example of the use of this program,
Packit 7cfc04
running a shell in a new mount namespace,
Packit 7cfc04
and verifying that the original shell and the
Packit 7cfc04
new shell are in separate mount namespaces:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
$ \fBreadlink /proc/$$/ns/mnt\fP
Packit 7cfc04
mnt:[4026531840]
Packit 7cfc04
$ \fBsudo ./unshare -m /bin/bash\fP
Packit 7cfc04
# \fBreadlink /proc/$$/ns/mnt\fP
Packit 7cfc04
mnt:[4026532325]
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
The differing output of the two
Packit 7cfc04
.BR readlink (1)
Packit 7cfc04
commands shows that the two shells are in different mount namespaces.
Packit 7cfc04
.SS Program source
Packit 7cfc04
\&
Packit 7cfc04
.EX
Packit 7cfc04
/* unshare.c
Packit 7cfc04
Packit 7cfc04
   A simple implementation of the unshare(1) command: unshare
Packit 7cfc04
   namespaces and execute a command.
Packit 7cfc04
*/
Packit 7cfc04
#define _GNU_SOURCE
Packit 7cfc04
#include <sched.h>
Packit 7cfc04
#include <unistd.h>
Packit 7cfc04
#include <stdlib.h>
Packit 7cfc04
#include <stdio.h>
Packit 7cfc04
Packit 7cfc04
/* A simple error\-handling function: print an error message based
Packit 7cfc04
   on the value in \(aqerrno\(aq and terminate the calling process */
Packit 7cfc04
Packit 7cfc04
#define errExit(msg)    do { perror(msg); exit(EXIT_FAILURE); \\
Packit 7cfc04
                        } while (0)
Packit 7cfc04
Packit 7cfc04
static void
Packit 7cfc04
usage(char *pname)
Packit 7cfc04
{
Packit 7cfc04
    fprintf(stderr, "Usage: %s [options] program [arg...]\\n", pname);
Packit 7cfc04
    fprintf(stderr, "Options can be:\\n");
Packit 7cfc04
    fprintf(stderr, "    \-i   unshare IPC namespace\\n");
Packit 7cfc04
    fprintf(stderr, "    \-m   unshare mount namespace\\n");
Packit 7cfc04
    fprintf(stderr, "    \-n   unshare network namespace\\n");
Packit 7cfc04
    fprintf(stderr, "    \-p   unshare PID namespace\\n");
Packit 7cfc04
    fprintf(stderr, "    \-u   unshare UTS namespace\\n");
Packit 7cfc04
    fprintf(stderr, "    \-U   unshare user namespace\\n");
Packit 7cfc04
    exit(EXIT_FAILURE);
Packit 7cfc04
}
Packit 7cfc04
Packit 7cfc04
int
Packit 7cfc04
main(int argc, char *argv[])
Packit 7cfc04
{
Packit 7cfc04
    int flags, opt;
Packit 7cfc04
Packit 7cfc04
    flags = 0;
Packit 7cfc04
Packit 7cfc04
    while ((opt = getopt(argc, argv, "imnpuU")) != \-1) {
Packit 7cfc04
        switch (opt) {
Packit 7cfc04
        case \(aqi\(aq: flags |= CLONE_NEWIPC;        break;
Packit 7cfc04
        case \(aqm\(aq: flags |= CLONE_NEWNS;         break;
Packit 7cfc04
        case \(aqn\(aq: flags |= CLONE_NEWNET;        break;
Packit 7cfc04
        case \(aqp\(aq: flags |= CLONE_NEWPID;        break;
Packit 7cfc04
        case \(aqu\(aq: flags |= CLONE_NEWUTS;        break;
Packit 7cfc04
        case \(aqU\(aq: flags |= CLONE_NEWUSER;       break;
Packit 7cfc04
        default:  usage(argv[0]);
Packit 7cfc04
        }
Packit 7cfc04
    }
Packit 7cfc04
Packit 7cfc04
    if (optind >= argc)
Packit 7cfc04
        usage(argv[0]);
Packit 7cfc04
Packit 7cfc04
    if (unshare(flags) == \-1)
Packit 7cfc04
        errExit("unshare");
Packit 7cfc04
Packit 7cfc04
    execvp(argv[optind], &argv[optind]);
Packit 7cfc04
    errExit("execvp");
Packit 7cfc04
}
Packit 7cfc04
.EE
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR unshare (1),
Packit 7cfc04
.BR clone (2),
Packit 7cfc04
.BR fork (2),
Packit 7cfc04
.BR kcmp (2),
Packit 7cfc04
.BR setns (2),
Packit 7cfc04
.BR vfork (2),
Packit 7cfc04
.BR namespaces (7)
Packit 7cfc04
.PP
Packit 7cfc04
.I Documentation/userspace-api/unshare.rst
Packit 7cfc04
in the Linux kernel source tree
Packit 7cfc04
.\" commit f504d47be5e8fa7ecf2bf660b18b42e6960c0eb2
Packit 7cfc04
(or
Packit 7cfc04
.I Documentation/unshare.txt
Packit 7cfc04
before Linux 4.12)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.