diff options
author | lns <matzeton@googlemail.com> | 2018-04-28 12:08:54 +0200 |
---|---|---|
committer | lns <matzeton@googlemail.com> | 2018-04-28 12:08:54 +0200 |
commit | b38788d83796f12e6bb060b11ab7b843c4340c99 (patch) | |
tree | a7d118c1f91ff34d6a35d414b7eaa370a4a5a548 /src/utils.c | |
parent | 45e0049315f9ca7e68a97fcfa73778f1c5dc1d75 (diff) |
POTD skeleton #36.
Signed-off-by: lns <matzeton@googlemail.com>
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/utils.c b/src/utils.c index ac0856c..8b89b6a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -11,6 +11,7 @@ #include <sys/stat.h> #include <sys/wait.h> #include <sys/prctl.h> +#include <sys/mount.h> #include <assert.h> #include "utils.h" @@ -229,26 +230,37 @@ int safe_chroot(const char *newroot) int dir_is_mountpoint(const char *path) { - struct stat current, parent; + struct stat current = {0}, parent = {0}; size_t plen = strlen(path); char parent_path[plen + 4]; if (stat(path, ¤t)) - return -1; + goto error; + strncpy(parent_path, path, plen); parent_path[plen] = '/'; parent_path[plen+1] = '.'; parent_path[plen+2] = '.'; parent_path[plen+3] = 0; if (stat(parent_path, &parent)) - return -1; + goto error; - return current.st_dev == parent.st_dev; + return current.st_dev != parent.st_dev; +error: + W_STRERR("Mountpoint check"); + return -1; } int mount_dev(const char *mount_path) { - if (!mount_path) { + int s; + + s = mount("dev", mount_path, "devtmpfs", + 0, + "rw,nosuid,relatime,size=4k,mode=755"); + if (s) { + E_STRERR("Mount /dev"); + return 1; } return 0; |