Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EXAMPLE
- The program below provides a simple implementation of the unshare(1)
- command, which unshares one or more namespaces and executes the command
- supplied in its command-line arguments. Here's an example of the use
- of this program, running a shell in a new mount namespace, and
- verifying that the original shell and the new shell are in separate
- mount namespaces:
- $ readlink /proc/$$/ns/mnt
- mnt:[4026531840]
- $ sudo ./unshare -m /bin/bash
- [sudo] password for cecilia:
- # readlink /proc/$$/ns/mnt
- mnt:[4026532325]
- The differing output of the two readlink(1) commands shows that the two
- shells are in different mount namespaces.
- Program source
- /* unshare.c
- A simple implementation of the unshare(1) command: unshare
- namespaces and execute a command.
- */
- #define _GNU_SOURCE
- #include <sched.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <stdio.h>
- /* A simple error-handling function: print an error message based
- on the value in 'errno' and terminate the calling process */
- #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \
- } while (0)
- static void
- usage(char *pname)
- {
- fprintf(stderr, "Usage: %s [options] program [arg...]\n", pname);
- fprintf(stderr, "Options can be:\n");
- fprintf(stderr, " -i unshare IPC namespace\n");
- fprintf(stderr, " -m unshare mount namespace\n");
- fprintf(stderr, " -n unshare network namespace\n");
- fprintf(stderr, " -p unshare PID namespace\n");
- fprintf(stderr, " -u unshare UTS namespace\n");
- fprintf(stderr, " -U unshare user namespace\n");
- exit(EXIT_FAILURE);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement