]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/freezer.c
lxc: child failing before container rename
[mirror_lxc.git] / src / lxc / freezer.c
CommitLineData
0ad19a3f 1/*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
7 * Daniel Lezcano <dlezcano at fr.ibm.com>
8 *
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.
13 *
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.
18 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23#define _GNU_SOURCE
24#include <stdio.h>
25#undef _GNU_SOURCE
26#include <stdlib.h>
27#include <errno.h>
28#include <unistd.h>
29#include <string.h>
30#include <fcntl.h>
31#include <sys/types.h>
0ad19a3f 32#include <sys/param.h>
0ad19a3f 33
e2bcd7db 34#include "error.h"
00b3c2e2 35
36eb9bde 36#include <lxc/log.h>
00b3c2e2 37#include <lxc/cgroup.h>
36eb9bde
CLG
38
39lxc_log_define(lxc_freezer, lxc);
0ad19a3f 40
41static int freeze_unfreeze(const char *name, int freeze)
42{
14ad6bfd 43 char *nsgroup;
84701151 44 char freezer[MAXPATHLEN], *f;
14ad6bfd 45 int fd, ret;
0ad19a3f 46
14ad6bfd
MN
47 ret = lxc_cgroup_path_get(&nsgroup, name);
48 if (ret)
49 return -1;
50
51 snprintf(freezer, MAXPATHLEN, "%s/freezer.state", nsgroup);
0ad19a3f 52
53 fd = open(freezer, O_WRONLY);
54 if (fd < 0) {
36eb9bde 55 SYSERROR("failed to open freezer for '%s'", name);
06efeb5c 56 return -1;
0ad19a3f 57 }
58
84701151 59 if (freeze) {
60 f = "FROZEN";
61 ret = write(fd, f, strlen(f) + 1) < 0;
62 } else {
63 f = "THAWED";
64 ret = write(fd, f, strlen(f) + 1) < 0;
65
66 /* compatibility code with old freezer interface */
67 if (ret) {
68 f = "RUNNING";
69 ret = write(fd, f, strlen(f) + 1) < 0;
70 }
71 }
72
0ad19a3f 73 close(fd);
74 if (ret)
36eb9bde 75 SYSERROR("failed to write to '%s'", freezer);
06efeb5c 76
14ad6bfd 77 return ret;
0ad19a3f 78}
79
80int lxc_freeze(const char *name)
81{
66aeffc7 82 return freeze_unfreeze(name, 1);
0ad19a3f 83}
84
85int lxc_unfreeze(const char *name)
86{
66aeffc7 87 return freeze_unfreeze(name, 0);
0ad19a3f 88}
89