Add tini unshare

This commit is contained in:
Sargun Dhillon 2018-04-30 09:52:40 -07:00
parent 436f0d0274
commit 49a72e53b8
1 changed files with 13 additions and 0 deletions

View File

@ -13,6 +13,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <stdbool.h> #include <stdbool.h>
#include <sched.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
@ -32,6 +33,7 @@
#define TITUS_CB_PATH "TITUS_UNIX_CB_PATH" #define TITUS_CB_PATH "TITUS_UNIX_CB_PATH"
#define TITUS_CONFIRM "TITUS_CONFIRM" #define TITUS_CONFIRM "TITUS_CONFIRM"
#define TINI_HANDOFF "TINI_HANDOFF" #define TINI_HANDOFF "TINI_HANDOFF"
#define TINI_UNSHARE "TINI_UNSHARE"
const char stdioattr[] = "user.stdio"; const char stdioattr[] = "user.stdio";
@ -169,6 +171,7 @@ int do_execvp(char* const argv[], int new_stdout_fd, int new_stderr_fd, const si
unsetenv(TITUS_CB_PATH); unsetenv(TITUS_CB_PATH);
unsetenv(TITUS_CONFIRM); unsetenv(TITUS_CONFIRM);
unsetenv(TINI_HANDOFF); unsetenv(TINI_HANDOFF);
unsetenv(TINI_UNSHARE);
execvp(argv[0], argv); execvp(argv[0], argv);
@ -219,6 +222,16 @@ int spawn(const signal_configuration_t* const sigconf_ptr, char* const argv[], i
return 1; return 1;
} }
} }
// Should unshare happen here, or in do_execvp / the child?
if (getenv(TINI_UNSHARE)) {
if (unshare(CLONE_NEWCGROUP)) {
PRINT_FATAL("Unable to unshare new cgroup namespace: %s", strerror(errno));
return 1;
}
}
if (getenv(TINI_HANDOFF)) if (getenv(TINI_HANDOFF))
return do_execvp(argv, new_stdout_fd, new_stderr_fd, sigconf_ptr); return do_execvp(argv, new_stdout_fd, new_stderr_fd, sigconf_ptr);