[CRIU] [PATCH 1/2] cgroup: only write one device entry at a time

Tycho Andersen tycho.andersen at canonical.com
Fri Jul 8 08:09:55 PDT 2016


We seem to have some reports of:

Error (cgroup.c:1193): cg: Failed writing c *:* m
b *:* m
c 1:3 rwm
c 1:5 rwm
c 1:7 rwm
c 5:0 rwm
c 5:2 rwm
c 1:8 rwm
c 1:9 rwm
c 136:* rwm
c 10:229 rwm to devices//lxc/c7/devices.allow: Argument list too long

so let's try and write these lines one by one, instead of simply advancing
the pointer along in the string. It's probably cleaner this way anyway :)

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
CC: Adrian Reber <adrian at lisas.de>
---
 criu/cgroup.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/criu/cgroup.c b/criu/cgroup.c
index c0f561c..72d80c4 100644
--- a/criu/cgroup.c
+++ b/criu/cgroup.c
@@ -1246,12 +1246,13 @@ static void add_freezer_state_for_restore(CgroupPropEntry *entry, char *path, si
 	freezer_path[path_len] = 0;
 }
 
-static void advance_device_entry(char **buf)
+static int next_device_entry(char *buf)
 {
-	char *pos = *buf;
+	char *pos = buf;
 
 	while (1) {
 		if (*pos == '\n') {
+			*pos = '\0';
 			pos++;
 			break;
 		} else if (*pos == '\0') {
@@ -1261,7 +1262,7 @@ static void advance_device_entry(char **buf)
 		pos++;
 	}
 
-	*buf = pos;
+	return pos - buf;
 }
 
 static int prepare_cgroup_dir_properties(char *path, int off, CgroupDirEntry **ents,
@@ -1346,13 +1347,16 @@ static int prepare_cgroup_dir_properties(char *path, int off, CgroupDirEntry **e
 					}
 					xfree(old_name);
 
-					for (pos = pe->value; *pos; advance_device_entry(&pos)) {
+					pos = pe->value;
+					while (*pos) {
+						int offset = next_device_entry(pos);
 						pe->value = pos;
 						ret = restore_cgroup_prop(pe, path, off2);
 						if (ret < 0) {
 							pe->value = old_val;
 							return -1;
 						}
+						pos += offset;
 					}
 					pe->value = old_val;
 
-- 
2.7.4



More information about the CRIU mailing list