aboutsummaryrefslogtreecommitdiffstats
path: root/util/tmpmount.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/tmpmount.c')
-rw-r--r--util/tmpmount.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/util/tmpmount.c b/util/tmpmount.c
new file mode 100644
index 0000000..75e225d
--- /dev/null
+++ b/util/tmpmount.c
@@ -0,0 +1,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;
+}