~serge-hallyn/ubuntu/quantal/lxc/lxc-guest-start-roroot

« back to all changes in this revision

Viewing changes to debian/patches/0211-lxc-conf-root-ro-option

  • Committer: Serge Hallyn
  • Date: 2012-09-06 15:25:06 UTC
  • Revision ID: serge.hallyn@ubuntu.com-20120906152506-xbq1lfduirgxar9b
setup_devpts before marking ro, and that in turn before pivot_root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
Index: lxc/src/lxc/conf.c
2
2
===================================================================
3
3
--- lxc.orig/src/lxc/conf.c     2012-09-05 11:29:37.360312431 -0500
4
 
+++ lxc/src/lxc/conf.c  2012-09-05 23:24:53.627247505 -0500
5
 
@@ -2234,6 +2234,15 @@
6
 
                return -1;
7
 
        }
8
 
 
 
4
+++ lxc/src/lxc/conf.c  2012-09-06 10:24:56.783811342 -0500
 
5
@@ -879,33 +879,45 @@
 
6
 static int setup_pts(int pts)
 
7
 {
 
8
        char target[PATH_MAX];
 
9
+       char t1[PATH_MAX], t2[PATH_MAX];
 
10
+       int ret;
 
11
 
 
12
        if (!pts)
 
13
                return 0;
 
14
 
 
15
+       ret = snprintf(t1, PATH_MAX, "%s/dev/pts");
 
16
+       if (ret < 0)
 
17
+               return -1;
 
18
+       ret = snprintf(t2, PATH_MAX, "%s/dev/pts/ptmx");
 
19
+       if (ret < 0)
 
20
+               return -1;
 
21
+       ret = snprintf(t3, PATH_MAX, "%s/dev/ptmx");
 
22
+       if (ret < 0)
 
23
+               return -1;
 
24
        if (!access("/dev/pts/ptmx", F_OK) && umount("/dev/pts")) {
 
25
+       if (!access(t2, F_OK) && umount(t1)) {
 
26
                SYSERROR("failed to umount 'dev/pts'");
 
27
                return -1;
 
28
        }
 
29
 
 
30
-       if (mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL,
 
31
+       if (mount("devpts", t1, "devpts", MS_MGC_VAL,
 
32
                  "newinstance,ptmxmode=0666")) {
 
33
                SYSERROR("failed to mount a new instance of '/dev/pts'");
 
34
                return -1;
 
35
        }
 
36
 
 
37
-       if (access("/dev/ptmx", F_OK)) {
 
38
-               if (!symlink("/dev/pts/ptmx", "/dev/ptmx"))
 
39
+       if (access(t3, F_OK)) {
 
40
+               if (!symlink(t2, t3))
 
41
                        goto out;
 
42
                SYSERROR("failed to symlink '/dev/pts/ptmx'->'/dev/ptmx'");
 
43
                return -1;
 
44
        }
 
45
 
 
46
-       if (realpath("/dev/ptmx", target) && !strcmp(target, "/dev/pts/ptmx"))
 
47
+       if (realpath(t3, target) && !strcmp(target, t2))
 
48
                goto out;
 
49
 
 
50
        /* fallback here, /dev/pts/ptmx exists just mount bind */
 
51
-       if (mount("/dev/pts/ptmx", "/dev/ptmx", "none", MS_BIND, 0)) {
 
52
+       if (mount(t2, t3, "none", MS_BIND, 0)) {
 
53
                SYSERROR("mount failed '/dev/pts/ptmx'->'/dev/ptmx'");
 
54
                return -1;
 
55
        }
 
56
@@ -2224,13 +2236,22 @@
 
57
                lxc_conf->umount_proc = 1;
 
58
        }
 
59
 
 
60
-       if (setup_pivot_root(&lxc_conf->rootfs)) {
 
61
-               ERROR("failed to set rootfs for '%s'", name);
 
62
+       if (setup_pts(lxc_conf->rootfs, lxc_conf->pts)) {
 
63
+               ERROR("failed to setup the new pts instance");
 
64
                return -1;
 
65
        }
 
66
 
 
67
-       if (setup_pts(lxc_conf->pts)) {
 
68
-               ERROR("failed to setup the new pts instance");
9
69
+       if (lxc_conf->rootfs.ro) {
10
70
+               if (mount("/", "/",
11
71
+                       "none", MS_BIND | MS_REMOUNT | MS_RDONLY, NULL)) {
15
75
+               DEBUG("remounted rootfs readonly");
16
76
+       }
17
77
+
18
 
        if (setup_personality(lxc_conf->personality)) {
19
 
                ERROR("failed to setup personality");
 
78
+       if (setup_pivot_root(&lxc_conf->rootfs)) {
 
79
+               ERROR("failed to set rootfs for '%s'", name);
20
80
                return -1;
 
81
        }
 
82
 
21
83
Index: lxc/src/lxc/conf.h
22
84
===================================================================
23
85
--- lxc.orig/src/lxc/conf.h     2012-09-05 10:06:17.065918000 -0500