mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-01-03 07:31:54 +00:00
Flock: Mounting cleanup
This commit is contained in:
parent
14478dad2f
commit
23a3e48db4
@ -78,6 +78,8 @@ container_poweroff(int fd, int sig)
|
|||||||
cbor_add_int(cw, -4);
|
cbor_add_int(cw, -4);
|
||||||
cbor_add_int(cw, sig);
|
cbor_add_int(cw, sig);
|
||||||
ASSERT_DIE(write(fd, outbuf, cw->pt) == cw->pt);
|
ASSERT_DIE(write(fd, outbuf, cw->pt) == cw->pt);
|
||||||
|
|
||||||
|
unlink("/dev/log");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -322,10 +324,10 @@ container_mainloop(int fd)
|
|||||||
SYSCALL(lstat, "/" #path, &s); \
|
SYSCALL(lstat, "/" #path, &s); \
|
||||||
switch (s.st_mode & S_IFMT) { \
|
switch (s.st_mode & S_IFMT) { \
|
||||||
case S_IFLNK: \
|
case S_IFLNK: \
|
||||||
copylink("/" #path, s.st_size, "./root/" #path); \
|
copylink("/" #path, s.st_size, "./lower/" #path); \
|
||||||
break; \
|
break; \
|
||||||
case S_IFDIR: \
|
case S_IFDIR: \
|
||||||
close(GETDIR(lp_strdup(lp, "./root/" #path))); \
|
close(GETDIR(lp_strdup(lp, "./lower/" #path))); \
|
||||||
SYSCALL(mount, "/" #path, "./root/" #path, NULL, MS_BIND | MS_REC, NULL); \
|
SYSCALL(mount, "/" #path, "./root/" #path, NULL, MS_BIND | MS_REC, NULL); \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
@ -339,14 +341,17 @@ container_mainloop(int fd)
|
|||||||
BINDMOUNT(sbin);
|
BINDMOUNT(sbin);
|
||||||
BINDMOUNT(usr);
|
BINDMOUNT(usr);
|
||||||
|
|
||||||
close(GETDIR(lp_strdup(lp, "./lower/dev")));
|
close(GETDIR(lp_strdup(lp, "./lower/dev/pts")));
|
||||||
|
symlink("/dev/pts/ptmx", "./lower/dev/ptmx");
|
||||||
|
|
||||||
DIR *x = opendir("/dev");
|
DIR *x = opendir("/dev");
|
||||||
for (struct dirent *e; e = readdir(x); )
|
for (struct dirent *e; e = readdir(x); )
|
||||||
{
|
{
|
||||||
if (!strcmp(e->d_name, ".")
|
if (!strcmp(e->d_name, ".")
|
||||||
|| !strcmp(e->d_name, "..")
|
|| !strcmp(e->d_name, "..")
|
||||||
|| !strcmp(e->d_name, "ptmx"))
|
|| !strcmp(e->d_name, "ptmx")
|
||||||
|
|| !strcmp(e->d_name, "log")
|
||||||
|
)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const char *path = lp_sprintf(lp, "./lower/dev/%s", e->d_name);
|
const char *path = lp_sprintf(lp, "./lower/dev/%s", e->d_name);
|
||||||
@ -386,27 +391,21 @@ container_mainloop(int fd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MKDIR("./lower/proc");
|
||||||
|
MKDIR("./lower/sys");
|
||||||
|
MKDIR("./lower/run");
|
||||||
|
MKDIR("./lower/tmp");
|
||||||
|
|
||||||
SYSCALL(chroot, "./root");
|
SYSCALL(chroot, "./root");
|
||||||
SYSCALL(chdir, "/");
|
SYSCALL(chdir, "/");
|
||||||
|
|
||||||
/* Remounting proc to reflect the new PID namespace */
|
/* Remounting proc to reflect the new PID namespace */
|
||||||
MKDIR("/proc");
|
|
||||||
SYSCALL(mount, "proc", "/proc", "proc", MS_NOSUID | MS_NODEV | MS_NOEXEC, NULL);
|
SYSCALL(mount, "proc", "/proc", "proc", MS_NOSUID | MS_NODEV | MS_NOEXEC, NULL);
|
||||||
|
|
||||||
MKDIR("/sys");
|
|
||||||
SYSCALL(mount, "sysfs", "/sys", "sysfs", MS_NOSUID | MS_NODEV | MS_NOEXEC, NULL);
|
SYSCALL(mount, "sysfs", "/sys", "sysfs", MS_NOSUID | MS_NODEV | MS_NOEXEC, NULL);
|
||||||
|
|
||||||
MKDIR("/run");
|
|
||||||
SYSCALL(mount, "tmpfs", "/run", "tmpfs", MS_NOSUID | MS_NODEV, NULL);
|
SYSCALL(mount, "tmpfs", "/run", "tmpfs", MS_NOSUID | MS_NODEV, NULL);
|
||||||
|
|
||||||
MKDIR("/tmp");
|
|
||||||
SYSCALL(mount, "tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV, NULL);
|
SYSCALL(mount, "tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV, NULL);
|
||||||
|
|
||||||
MKDIR("/dev/pts");
|
|
||||||
SYSCALL(mount, "devpts", "/dev/pts", "devpts", MS_NOSUID | MS_NOEXEC, "ptmxmode=600");
|
SYSCALL(mount, "devpts", "/dev/pts", "devpts", MS_NOSUID | MS_NOEXEC, "ptmxmode=600");
|
||||||
|
|
||||||
symlink("/dev/pts/ptmx", "/dev/ptmx");
|
|
||||||
|
|
||||||
container_init_logger();
|
container_init_logger();
|
||||||
|
|
||||||
/* Run worker threads */
|
/* Run worker threads */
|
||||||
|
Loading…
Reference in New Issue
Block a user