initial commit
This commit is contained in:
commit
a4395189ad
5 changed files with 608 additions and 0 deletions
31
setns.c
Normal file
31
setns.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
#define _GNU_SOURCE
|
||||
#include <fcntl.h>
|
||||
#include <sched.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \
|
||||
} while (0)
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "%s /proc/PID/ns/FILE cmd args...\n", argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
fd = open(argv[1], O_RDONLY); /* Get descriptor for namespace */
|
||||
if (fd == -1)
|
||||
errExit("open");
|
||||
|
||||
//if (setns(fd, CLONE_NEWNS) == -1)
|
||||
if (setns(fd, 0) == -1) /* Join that namespace */
|
||||
errExit("setns");
|
||||
|
||||
execvp(argv[2], &argv[2]); /* Execute a command in namespace */
|
||||
errExit("execvp");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue