From: Serge Hallyn Date: Fri, 8 Feb 2013 23:32:32 +0000 (-0600) Subject: add lxc-unshare man page, and make 'lxc-unshare -h' work. X-Git-Tag: lxc-0.9.0.alpha3~1^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=810567bbbe283c547e4ac837545d1e592916df26;p=thirdparty%2Flxc.git add lxc-unshare man page, and make 'lxc-unshare -h' work. Also fix some tabs-as-spaces in lxc_unshare.c itself. lxc-unshare: run usage() on '-h' Signed-off-by: Serge Hallyn Acked-by: Stéphane Graber --- diff --git a/configure.ac b/configure.ac index 6402024fb..eb4b714e3 100644 --- a/configure.ac +++ b/configure.ac @@ -326,6 +326,7 @@ AC_CONFIG_FILES([ doc/common_options.sgml doc/see_also.sgml doc/legacy/lxc-ls.sgml + doc/lxc-unshare.sgml doc/rootfs/Makefile diff --git a/doc/Makefile.am b/doc/Makefile.am index e54a08782..750398cd1 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -18,6 +18,7 @@ man_MANS = \ lxc-console.1 \ lxc-freeze.1 \ lxc-unfreeze.1 \ + lxc-unshare.1 \ lxc-monitor.1 \ lxc-wait.1 \ lxc-ps.1 \ diff --git a/doc/lxc-unshare.sgml.in b/doc/lxc-unshare.sgml.in new file mode 100644 index 000000000..4132d4cfb --- /dev/null +++ b/doc/lxc-unshare.sgml.in @@ -0,0 +1,161 @@ + + + + +]> + + + + @LXC_GENERATE_DATE@ + + + lxc-unshare + 1 + + + + lxc-unshare + + + Run a task in a new set of namespaces. + + + + + + lxc-clone + -s namespaces + -u user + command + + + + + Description + + + lxc-unshare can be used to run a task in a cloned set + of namespaces. This command is mainly provided for testing purposes. + Despite its name, it always uses clone rather than unshare to create + the new task with fresh namespaces. Apart from testing kernel + regressions this should make no difference. + + + + + + + Options + + + + + + + + + + Specify the namespaces to attach to, as a pipe-separated list, + e.g. NETWORK|IPC. Allowed values are + MOUNT, PID, + UTSNAME, IPC, + USER and + NETWORK. This allows one to change + the context of the process to e.g. the network namespace of the + container while retaining the other namespaces as those of the + host. + + + + + + + + + + + Specify a user which the new task should become. This option is + only valid if a user namespace is unshared. + + + + + + + + + + Examples + + To spawn a new shell with its own UTS (hostname) namespace, + + lxc-clone -s UTSNAME /bin/bash + + If the hostname is changed in that shell, the change will not be + reflected on the host. + + + To spawn a shell in a new network, pid, and mount namespace, + + lxc-clone -s "NETWORK|PID|MOUNT" /bin/bash + + The resulting shell will have pid 1 and will see no network interfaces. + After re-mounting /proc in that shell, + + mount -t proc proc /proc + + ps output will show there are no other processes in the namespace. + + + + &seealso; + + + Author + Daniel Lezcano daniel.lezcano@free.fr + + + + + diff --git a/src/lxc/lxc_unshare.c b/src/lxc/lxc_unshare.c index df91456d8..d92a96a8f 100644 --- a/src/lxc/lxc_unshare.c +++ b/src/lxc/lxc_unshare.c @@ -125,11 +125,13 @@ int main(int argc, char *argv[]) .flags = &flags, }; - while ((opt = getopt(argc, argv, "s:u:")) != -1) { + while ((opt = getopt(argc, argv, "s:u:h")) != -1) { switch (opt) { case 's': namespaces = optarg; break; + case 'h': + usage(argv[0]); case 'u': uid = lookup_user(optarg); if (uid == -1) @@ -137,10 +139,10 @@ int main(int argc, char *argv[]) } } - if (argv[optind] == NULL) { - ERROR("a command to execute in the new namespace is required"); - return 1; - } + if (argv[optind] == NULL) { + ERROR("a command to execute in the new namespace is required"); + return 1; + } args = &argv[optind]; @@ -148,8 +150,8 @@ int main(int argc, char *argv[]) if (ret) return ret; - ret = lxc_fill_namespace_flags(namespaces, &flags); - if (ret) + ret = lxc_fill_namespace_flags(namespaces, &flags); + if (ret) usage(argv[0]); if (!(flags & CLONE_NEWUSER) && uid != -1) {