.
This commit is contained in:
parent
7510c2a7b3
commit
73b2f7f3b5
10 changed files with 67 additions and 35 deletions
|
@ -9,14 +9,12 @@ void procfs_prepare()
|
|||
#define hostname "runner"
|
||||
|
||||
#define put_old "oldfs"
|
||||
void mnt_prepare(char* rootfs, char* shared_mountpoint) {
|
||||
char* shared_folder = NULL;
|
||||
asprintf(&shared_folder, "../%s", shared_mountpoint);
|
||||
void mnt_prepare(char* rootfs, char* shared_folder) {
|
||||
if (mount(rootfs, rootfs, "ext4", MS_BIND,"")) die("failed to mount %s: %m", rootfs);
|
||||
if (chdir(rootfs)) die("falied to cd:%m");
|
||||
//if (mount("/sys","sys","sysfs",0,"")) die("failed to mount sysfs: %m");
|
||||
//if (mount("/dev","dev","udev",0,"")) die("failed to mount: %m");
|
||||
if (mkdir("shared", 0777) && errno != EEXIST) die("Failed to mkdir %s: %m\n", shared_mountpoint);
|
||||
if (mkdir("shared", 0777) && errno != EEXIST) die("Failed to mkdir: %m\n");
|
||||
if (mount(shared_folder, "shared", "ext4", MS_BIND, "")) die("failed to mount shared folder: %m");
|
||||
if (mkdir(put_old, 0000) && errno != EEXIST) die("Failed to mkdir %s: %m\n", put_old);
|
||||
if (syscall(SYS_pivot_root, ".", put_old)) die("Failed to pivot_root from %s to %s: %m\n", rootfs, put_old);
|
||||
|
@ -24,7 +22,6 @@ void mnt_prepare(char* rootfs, char* shared_mountpoint) {
|
|||
procfs_prepare();
|
||||
if (umount2(put_old, MNT_DETACH)) die("Failed to umount put_old %s: %m\n", put_old);
|
||||
if (rmdir(put_old)) die("Failed to rmdir: %m");
|
||||
free(shared_folder);
|
||||
}
|
||||
void ro_fs(char* shared_mountpoint) {
|
||||
char* shared_folder = malloc(strlen(shared_mountpoint)+4);
|
||||
|
@ -69,7 +66,7 @@ int nsrun(void* arg) {
|
|||
char* env[]={
|
||||
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
||||
"PWD=/",
|
||||
NULL,
|
||||
(char*)0,
|
||||
};
|
||||
if (execve(cmd, argv, env) == -1) die("failed to exec,%m");
|
||||
return 1;// removes warning
|
||||
|
|
|
@ -48,13 +48,12 @@ static void prepare_userns(int pid) {
|
|||
write_file(path, line);
|
||||
}
|
||||
|
||||
int starter(char* working_path, struct limits limits, struct params params) {
|
||||
int starter(char* shared_folder, char* minrootfs_path, struct limits limits, struct params params) {
|
||||
puts("starter started");
|
||||
if(setuid(0)) die("must be run as root");
|
||||
if(setgid(0)) die("must be run as root");
|
||||
// get binary path
|
||||
char* real_path=working_path;
|
||||
//get_real_path(real_path, argv[0]);
|
||||
if(chdir(real_path)) die("unable to chdir to binary path: %m");
|
||||
if(chdir(minrootfs_path)) die("unable to chdir: %m");
|
||||
// set random seed
|
||||
srand(time(NULL));
|
||||
// setup parameters
|
||||
|
|
|
@ -51,3 +51,4 @@ extern void await_setup(int pipe);
|
|||
extern int nsrun(void* arg);
|
||||
extern void die_func(const char *fmt, ...);
|
||||
extern void write_file(char* path, char* line);
|
||||
extern int starter(char* shared_folder, char* minrootfs_path, struct limits limits, struct params params);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue