]>
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 <dlezcano at fr.ibm.com>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <sys/types.h>
32 #include <sys/param.h>
37 #include <lxc/cgroup.h>
39 lxc_log_define(lxc_freezer
, lxc
);
41 static int freeze_unfreeze(const char *name
, int freeze
)
44 char freezer
[MAXPATHLEN
], *f
;
48 ret
= lxc_cgroup_path_get(&nsgroup
, "freezer", name
);
52 ret
= snprintf(freezer
, MAXPATHLEN
, "%s/freezer.state", nsgroup
);
53 if (ret
>= MAXPATHLEN
) {
54 ERROR("freezer.state name too long");
58 fd
= open(freezer
, O_RDWR
);
60 SYSERROR("failed to open freezer for '%s'", name
);
66 ret
= write(fd
, f
, strlen(f
) + 1);
69 ret
= write(fd
, f
, strlen(f
) + 1);
71 /* compatibility code with old freezer interface */
74 ret
= write(fd
, f
, strlen(f
) + 1) < 0;
79 SYSERROR("failed to write '%s' to '%s'", f
, freezer
);
84 ret
= lseek(fd
, 0L, SEEK_SET
);
86 SYSERROR("failed to lseek on file '%s'", freezer
);
90 ret
= read(fd
, tmpf
, sizeof(tmpf
));
92 SYSERROR("failed to read to '%s'", freezer
);
96 ret
= strncmp(f
, tmpf
, strlen(f
));
102 ret
= lseek(fd
, 0L, SEEK_SET
);
104 SYSERROR("failed to lseek on file '%s'", freezer
);
108 ret
= write(fd
, f
, strlen(f
) + 1);
110 SYSERROR("failed to write '%s' to '%s'", f
, freezer
);
120 int lxc_freeze(const char *name
)
122 return freeze_unfreeze(name
, 1);
125 int lxc_unfreeze(const char *name
)
127 return freeze_unfreeze(name
, 0);