Skip to content

Commit

Permalink
freezer: non-functional changes
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Feb 7, 2018
1 parent 10e5c67 commit 1bab0ca
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions src/lxc/freezer.c
Expand Up @@ -32,45 +32,57 @@
#include <sys/param.h>

#include "error.h"
#include "state.h"
#include "monitor.h"
#include "log.h"
#include "lxc.h"
#include "monitor.h"
#include "parse.h"
#include "state.h"

lxc_log_define(lxc_freezer, lxc);

lxc_state_t freezer_state(const char *name, const char *lxcpath)
{
int ret;
char v[100];
if (lxc_cgroup_get("freezer.state", v, 100, name, lxcpath) < 0)

ret = lxc_cgroup_get("freezer.state", v, 100, name, lxcpath);
if (ret < 0)
return -1;

if (v[strlen(v)-1] == '\n')
v[strlen(v)-1] = '\0';
v[99] = '\0';
v[lxc_char_right_gc(v, strlen(v))] = '\0';

return lxc_str2state(v);
}

static int do_freeze_thaw(int freeze, const char *name, const char *lxcpath)
{
int ret;
char v[100];
const char *state = freeze ? "FROZEN" : "THAWED";

if (lxc_cgroup_set("freezer.state", state, name, lxcpath) < 0) {
ERROR("Failed to freeze %s:%s", lxcpath, name);
ret = lxc_cgroup_set("freezer.state", state, name, lxcpath);
if (ret < 0) {
ERROR("Failed to freeze %s", name);
return -1;
}
while (1) {
if (lxc_cgroup_get("freezer.state", v, 100, name, lxcpath) < 0) {
ERROR("Failed to get new freezer state for %s:%s", lxcpath, name);

for (;;) {
ret = lxc_cgroup_get("freezer.state", v, 100, name, lxcpath);
if (ret < 0) {
ERROR("Failed to get freezer state of %s", name);
return -1;
}
if (v[strlen(v)-1] == '\n')
v[strlen(v)-1] = '\0';
if (strncmp(v, state, strlen(state)) == 0) {
if (name)
lxc_monitor_send_state(name, freeze ? FROZEN : THAWED, lxcpath);

v[99] = '\0';
v[lxc_char_right_gc(v, strlen(v))] = '\0';

ret = strncmp(v, state, strlen(state));
if (ret == 0) {
lxc_monitor_send_state(name, freeze ? FROZEN : THAWED, lxcpath);
return 0;
}

sleep(1);
}
}
Expand Down

0 comments on commit 1bab0ca

Please sign in to comment.