]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/freezer.c
2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <daniel.lezcano at free.fr>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31 #include <sys/types.h>
32 #include <sys/param.h>
42 lxc_log_define(lxc_freezer
, lxc
);
44 lxc_state_t
freezer_state(const char *name
, const char *lxcpath
)
49 ret
= lxc_cgroup_get("freezer.state", v
, sizeof(v
), name
, lxcpath
);
54 v
[lxc_char_right_gc(v
, strlen(v
))] = '\0';
56 return lxc_str2state(v
);
59 static int do_freeze_thaw(bool freeze
, const char *name
, const char *lxcpath
)
63 const char *state
= freeze
? "FROZEN" : "THAWED";
65 lxc_state_t new_state
= freeze
? FROZEN
: THAWED
;
67 ret
= lxc_cgroup_set("freezer.state", state
, name
, lxcpath
);
69 ERROR("Failed to freeze %s", name
);
74 ret
= lxc_cgroup_get("freezer.state", v
, sizeof(v
), name
, lxcpath
);
76 ERROR("Failed to get freezer state of %s", name
);
81 v
[lxc_char_right_gc(v
, strlen(v
))] = '\0';
83 ret
= strncmp(v
, state
, state_len
);
85 lxc_cmd_serve_state_clients(name
, lxcpath
, new_state
);
86 lxc_monitor_send_state(name
, new_state
, lxcpath
);
94 int lxc_freeze(const char *name
, const char *lxcpath
)
96 lxc_cmd_serve_state_clients(name
, lxcpath
, FREEZING
);
97 lxc_monitor_send_state(name
, FREEZING
, lxcpath
);
98 return do_freeze_thaw(true, name
, lxcpath
);
101 int lxc_unfreeze(const char *name
, const char *lxcpath
)
103 return do_freeze_thaw(false, name
, lxcpath
);