]> xenbits.xensource.com Git - people/liuw/rumprun.git/commitdiff
Mount a 1MB tmpfs on /tmp by default.
authorAntti Kantee <pooka@iki.fi>
Tue, 28 Apr 2015 14:00:34 +0000 (14:00 +0000)
committerAntti Kantee <pooka@iki.fi>
Tue, 28 Apr 2015 14:32:09 +0000 (14:32 +0000)
Prevents silly interactions with rumpfs for programs that write to /tmp.

lib/librumprun_base/rumprun.c

index 9a553a873cb3aefe6c97a660ad3ec1c469f5e27e..4f67462c6f204492b0ae71cc354e38882244c599 100644 (file)
  */
 
 #include <sys/types.h>
+#include <sys/mount.h>
 #include <sys/queue.h>
 
 #include <assert.h>
+#include <err.h>
+#include <errno.h>
 #include <pthread.h>
 #include <stdio.h>
 #include <sched.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #include <rump/rump.h>
 #include <rump/rump_syscalls.h>
 
+#include <fs/tmpfs/tmpfs_args.h>
+
 #include <bmk-core/platform.h>
 
 #include <rumprun-base/rumprun.h>
@@ -49,10 +55,20 @@ static pthread_cond_t w_cv;
 void
 rumprun_boot(const char *cmdline)
 {
+       struct tmpfs_args ta = {
+               .ta_version = TMPFS_ARGS_VERSION,
+               .ta_size_max = 1*1024*1024,
+               .ta_root_mode = 01777,
+       };
+       int tmpfserrno;
 
        rump_boot_setsigmodel(RUMP_SIGMODEL_IGNORE);
        rump_init();
 
+       /* mount /tmp before we let any userspace bits run */
+       rump_sys_mount(MOUNT_TMPFS, "/tmp", 0, &ta, sizeof(ta));
+       tmpfserrno = errno;
+
        /*
         * XXX: _netbsd_userlevel_init() should technically be called
         * in mainbouncer() per process.  However, there's currently no way
@@ -66,6 +82,13 @@ rumprun_boot(const char *cmdline)
        rumprun_lwp_init();
        _netbsd_userlevel_init();
 
+       /* print tmpfs result only after we bootstrapped userspace */
+       if (tmpfserrno == 0) {
+               fprintf(stderr, "mounted tmpfs on /tmp\n");
+       } else {
+               warnx("FAILED: mount tmpfs on /tmp: %s", strerror(tmpfserrno));
+       }
+
 #ifdef RUMP_SYSPROXY
        rump_init_server("tcp://0:12345");
 #endif