Change to the root mountpoint, if one exists.
authorDaniel Hokka Zakrisson <daniel@hozac.com>
Sun, 12 Sep 2010 00:38:48 +0000 (00:38 +0000)
committerDaniel Hokka Zakrisson <daniel@hozac.com>
Sun, 12 Sep 2010 00:38:48 +0000 (00:38 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2914 94cd875c-1c1d-0410-91d2-eb244daf1a30

src/secure-mount.c

index 1a3bc19..baf2c4a 100644 (file)
@@ -82,6 +82,7 @@ struct Options {
     bool               mount_all;
     RootFsOption       rootfs;
 
+    char               cur_dir_path[PATH_MAX];
     int                        cur_dir_fd;
     int                        cur_rootdir_fd;
 };
@@ -445,7 +446,7 @@ canHandleInternal(struct MountInfo const *mnt)
 }
 
 static bool
-mountSingle(struct MountInfo const *mnt, struct Options const *opt)
+mountSingle(struct MountInfo const *mnt, struct Options *opt)
 {
   assert(mnt->dst!=0);
   
@@ -459,6 +460,16 @@ mountSingle(struct MountInfo const *mnt, struct Options const *opt)
       perror("secure-mount: mount()");
       return false;
     }
+    if (strcmp(mnt->dst, "/") == 0) {
+      /* XXX: Hack */
+      if (chdir(opt->cur_dir_path) == -1) {
+       perror("secure-mount: chdir(.)");
+       return false;
+      }
+      close(opt->cur_dir_fd);
+      opt->cur_dir_fd = Eopen(".", O_RDONLY|O_DIRECTORY, 0);
+      Efcntl(opt->cur_dir_fd, F_SETFD, FD_CLOEXEC);
+    }
     if ((mnt->flag & MS_BIND) &&
        (mnt->mask & ~(MS_BIND|MS_REC))) {
       /* This is needed to put us in the new mountpoint */
@@ -607,7 +618,7 @@ adjustFileMount(struct MountInfo *mnt)
 }
 
 static bool
-mountFstab(struct Options const *opt)
+mountFstab(struct Options *opt)
 {
   bool         res = false;
   int          fd;
@@ -687,6 +698,11 @@ initFDs(struct Options *opt)
 
   Efcntl(opt->cur_dir_fd,     F_SETFD, FD_CLOEXEC);
   Efcntl(opt->cur_rootdir_fd, F_SETFD, FD_CLOEXEC);
+
+  if (getcwd(opt->cur_dir_path, sizeof(opt->cur_dir_path)) == NULL) {
+    perror("secure-mount: getcwd()");
+    exit(wrapper_exit_code);
+  }
 }
 
 static RootFsOption