1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
/* See LICENSE file for copyright and license details. */
#include <sys/mount.h>
#include <sched.h>
#include <libsimple.h>
#include <libsimple-arg.h>
NUSAGE(125, "mountpoint utility [argument] ...");
int
main(int argc, char *argv[])
{
const char *mountpoint;
libsimple_default_failure_exit = 125;
ARGBEGIN {
default:
usage();
} ARGEND;
if (argc < 2)
usage();
mountpoint = *argv++;
argc--;
if (unshare(CLONE_NEWNS))
eprintf("unshare CLONE_NEWNS:");
if (mount("none", "/", NULL, MS_REC | MS_SLAVE, NULL))
eprintf("mount none / NULL MS_REC|MS_SLAVE NULL:");
if (mount("tmpfs", mountpoint, "tmpfs", 0, NULL))
eprintf("mount tmpfs %s tmpfs 0 NULL:", mountpoint);
if (setegid(getgid()))
eprintf("setegid <real group>:");
if (seteuid(getuid()))
eprintf("seteuid <real user>:");
execvp(argv[0], argv);
enprintf(errno == ENOENT ? 127 : 126, "execvp %s:", argv[0]);
return 0;
}
|