Package: cgmanager / 0.33-2+deb8u2

bind-mount-old-root.patch Patch series | download
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
45
46
commit 55138814d2fedc8d71e2196f75b04d31970d1dad
Author: Serge Hallyn <serge.hallyn@ubuntu.com>
Date:   Fri Feb 13 13:44:59 2015 -0600

    pivot_root: bind-mount the old / rather than starting with empty /
    
    That way we get /lib and /etc which sometimes are needed.
    
    Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>

Index: cgmanager-0.33/fs.c
===================================================================
--- cgmanager-0.33.orig/fs.c
+++ cgmanager-0.33/fs.c
@@ -850,8 +850,7 @@ fail:
 
 static int pivot_into_new_root(void) {
 	int i, ret;
-	char *createdirs[] = {NEWROOT "/proc", NEWROOT "/run",
-		NEWROOT "/run/cgmanager", NEWROOT "/run/cgmanager/fs", NULL};
+	char *createdirs[] = {NEWROOT "/run/cgmanager", NEWROOT "/run/cgmanager/fs", NULL};
 	char path[100];
 
 	/* Mount tmpfs for new root */
@@ -859,16 +858,17 @@ static int pivot_into_new_root(void) {
 		nih_fatal("%s: Failed to create directory for new root\n", __func__);
 		return -1;
 	}
-	ret = mount("root", NEWROOT, "tmpfs", 0, "size=10000,mode=0755");
+	ret = mount("/", NEWROOT, NULL, MS_BIND, 0);
 	if (ret < 0) {
-		nih_fatal("%s: Failed to mount tmpfs for root", __func__);
+		nih_fatal("%s: Failed to bind-mount / for new root", __func__);
 		return -1;
 	}
 
 	/* create /proc and /run/cgmanager/fs, and move-mount those */
 	for (i = 0; createdirs[i]; i++) {
-		if (mkdir(createdirs[i], 0755) < 0) {
-			nih_fatal("%s: failed to created %s\n", __func__, createdirs[i]);
+		if (mkdir(createdirs[i], 0755) < 0 && errno != EEXIST) {
+			nih_fatal("%s: failed to create %s: %s\n", __func__,
+				createdirs[i], strerror(errno));
 			return -1;
 		}
 	}