diff options
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/src/utils.c b/src/utils.c index 8b89b6a..b4820d0 100644 --- a/src/utils.c +++ b/src/utils.c @@ -251,15 +251,38 @@ error: return -1; } +void chk_chroot(void) +{ + struct stat s = {0}; + + if (stat("/", &s) == 0) { + if (s.st_ino != 2) + return; + } + + E("%s", "Can not mount filesystem as slave"); + exit(EXIT_FAILURE); +} + +void mount_root(void) +{ + int s; + + s = mount(NULL, "/", "auto", MS_SLAVE|MS_REC, NULL); + if (s) + chk_chroot(); +} + int mount_dev(const char *mount_path) { int s; - s = mount("dev", mount_path, "devtmpfs", - 0, - "rw,nosuid,relatime,size=4k,mode=755"); + s = mount("tmpfs", mount_path, "tmpfs", + MS_NOSUID|MS_STRICTATIME| + MS_NOEXEC|MS_REC, + "size=4k,mode=755,gid=0"); if (s) { - E_STRERR("Mount /dev"); + E_STRERR("Mount devtmpfs filesystem"); return 1; } @@ -268,5 +291,21 @@ int mount_dev(const char *mount_path) int mount_pts(const char *mount_path) { + int s; + + s = mount("devpts", mount_path, "devpts", + MS_MGC_VAL, + "newinstance,gid=5,mode=620,ptmxmode=0666"); + + if (s) { + E_STRERR("Mount devpts filesystem"); + return 1; + } + + return 0; +} + +int create_device_files(const char *mount_path) +{ return 0; } |