[CRIU] [PATCH] seize: get_freezer_state -- Relax stack

Cyrill Gorcunov gorcunov at openvz.org
Wed Dec 9 05:57:06 PST 2015


For historical reason we allocate the complete PATH_MAX
here just to fetch a word of freezer state. Lets relax
the stack pressue and rename @path to @state. Same time
make states @frozen, @freezing, @thawed being static,
we don't export them.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 seize.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/seize.c b/seize.c
index de5c929a9d39..ca623fea28dd 100644
--- a/seize.c
+++ b/seize.c
@@ -20,35 +20,39 @@
 
 #define NR_ATTEMPTS 5
 
-const char frozen[]	= "FROZEN";
-const char freezing[]	= "FREEZING";
-const char thawed[]	= "THAWED";
+static const char frozen[]	= "FROZEN";
+static const char freezing[]	= "FREEZING";
+static const char thawed[]	= "THAWED";
 
 static const char *get_freezer_state(int fd)
 {
+	char state[32];
 	int ret;
-	char path[PATH_MAX];
+
+	BUILD_BUG_ON((sizeof(state) < sizeof(frozen))	||
+		     (sizeof(state) < sizeof(freezing))	||
+		     (sizeof(state) < sizeof(thawed)));
 
 	lseek(fd, 0, SEEK_SET);
-	ret = read(fd, path, sizeof(path) - 1);
+	ret = read(fd, state, sizeof(state) - 1);
 	if (ret <= 0) {
 		pr_perror("Unable to get a current state");
 		goto err;
 	}
-	if (path[ret - 1] == '\n')
-		path[ret - 1] = 0;
+	if (state[ret - 1] == '\n')
+		state[ret - 1] = 0;
 	else
-		path[ret] = 0;
+		state[ret] = 0;
 
-	pr_debug("freezer.state=%s\n", path);
-	if (strcmp(path, frozen) == 0)
+	pr_debug("freezer.state=%s\n", state);
+	if (strcmp(state, frozen) == 0)
 		return frozen;
-	if (strcmp(path, freezing) == 0)
+	else if (strcmp(state, freezing) == 0)
 		return freezing;
-	if (strcmp(path, thawed) == 0)
+	else if (strcmp(state, thawed) == 0)
 		return thawed;
 
-	pr_err("Unknown freezer state: %s\n", path);
+	pr_err("Unknown freezer state: %s\n", state);
 err:
 	return NULL;
 }
-- 
2.5.0



More information about the CRIU mailing list