Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. EXAMPLE
  2. The program below provides a simple implementation of the unshare(1)
  3. command, which unshares one or more namespaces and executes the command
  4. supplied in its command-line arguments. Here's an example of the use
  5. of this program, running a shell in a new mount namespace, and
  6. verifying that the original shell and the new shell are in separate
  7. mount namespaces:
  8.  
  9. $ readlink /proc/$$/ns/mnt
  10. mnt:[4026531840]
  11. $ sudo ./unshare -m /bin/bash
  12. [sudo] password for cecilia:
  13. # readlink /proc/$$/ns/mnt
  14. mnt:[4026532325]
  15.  
  16. The differing output of the two readlink(1) commands shows that the two
  17. shells are in different mount namespaces.
  18.  
  19. Program source
  20. /* unshare.c
  21.  
  22. A simple implementation of the unshare(1) command: unshare
  23. namespaces and execute a command.
  24. */
  25. #define _GNU_SOURCE
  26. #include <sched.h>
  27. #include <unistd.h>
  28. #include <stdlib.h>
  29. #include <stdio.h>
  30.  
  31. /* A simple error-handling function: print an error message based
  32. on the value in 'errno' and terminate the calling process */
  33.  
  34. #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \
  35. } while (0)
  36.  
  37. static void
  38. usage(char *pname)
  39. {
  40. fprintf(stderr, "Usage: %s [options] program [arg...]\n", pname);
  41. fprintf(stderr, "Options can be:\n");
  42. fprintf(stderr, " -i unshare IPC namespace\n");
  43. fprintf(stderr, " -m unshare mount namespace\n");
  44. fprintf(stderr, " -n unshare network namespace\n");
  45. fprintf(stderr, " -p unshare PID namespace\n");
  46. fprintf(stderr, " -u unshare UTS namespace\n");
  47. fprintf(stderr, " -U unshare user namespace\n");
  48. exit(EXIT_FAILURE);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement