[lxc-devel] [lxc/master] Update of freezer.c

Rachid-Koucha on Github lxc-bot at linuxcontainers.org
Sat Jan 26 20:56:52 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190126/05258517/attachment.bin>
-------------- next part --------------
From 72f1267d223235c012d4e816f4a44e7e4a5403a4 Mon Sep 17 00:00:00 2001
From: Rachid Koucha <47061324+Rachid-Koucha at users.noreply.github.com>
Date: Sat, 26 Jan 2019 21:11:23 +0100
Subject: [PATCH] Update of freezer.c

Make the source code auto-adapt to any future change in the names of the states
and the size of internal array
---
 src/lxc/freezer.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/lxc/freezer.c b/src/lxc/freezer.c
index 88f69222fa..e9755d1baf 100644
--- a/src/lxc/freezer.c
+++ b/src/lxc/freezer.c
@@ -51,10 +51,12 @@ static int do_freeze_thaw(bool freeze, struct lxc_conf *conf, const char *name,
 	int ret;
 	char v[100];
 	struct cgroup_ops *cgroup_ops;
-	const char *state = freeze ? "FROZEN" : "THAWED";
+        const char *state;
 	size_t state_len = 6;
 	lxc_state_t new_state = freeze ? FROZEN : THAWED;
 
+        state = lxc_state2str(new_state);
+
 	cgroup_ops = cgroup_init(conf);
 	if (!cgroup_ops)
 		return -1;
@@ -62,7 +64,7 @@ static int do_freeze_thaw(bool freeze, struct lxc_conf *conf, const char *name,
 	ret = cgroup_ops->set(cgroup_ops, "freezer.state", state, name, lxcpath);
 	if (ret < 0) {
 		cgroup_exit(cgroup_ops);
-		ERROR("Failed to freeze %s", name);
+		ERROR("Failed to %s %s", (new_state == FROZEN ? "freeze" : "unfreeze"), name);
 		return -1;
 	}
 
@@ -74,7 +76,7 @@ static int do_freeze_thaw(bool freeze, struct lxc_conf *conf, const char *name,
 			return -1;
 		}
 
-		v[99] = '\0';
+		v[sizeof(v)-1] = '\0';
 		v[lxc_char_right_gc(v, strlen(v))] = '\0';
 
 		ret = strncmp(v, state, state_len);


More information about the lxc-devel mailing list