]>
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>
39 #include <lxc/cgroup.h>
41 lxc_log_define(lxc_freezer
, lxc
);
43 static int do_unfreeze(const char *nsgroup
, int freeze
, const char *name
, const char *lxcpath
)
45 char freezer
[MAXPATHLEN
], *f
;
49 ret
= snprintf(freezer
, MAXPATHLEN
, "%s/freezer.state", nsgroup
);
50 if (ret
>= MAXPATHLEN
) {
51 ERROR("freezer.state name too long");
55 fd
= open(freezer
, O_RDWR
);
57 SYSERROR("failed to open freezer at '%s'", nsgroup
);
63 ret
= write(fd
, f
, strlen(f
) + 1);
66 ret
= write(fd
, f
, strlen(f
) + 1);
68 /* compatibility code with old freezer interface */
71 ret
= write(fd
, f
, strlen(f
) + 1) < 0;
76 SYSERROR("failed to write '%s' to '%s'", f
, freezer
);
81 ret
= lseek(fd
, 0L, SEEK_SET
);
83 SYSERROR("failed to lseek on file '%s'", freezer
);
87 ret
= read(fd
, tmpf
, sizeof(tmpf
));
89 SYSERROR("failed to read to '%s'", freezer
);
93 ret
= strncmp(f
, tmpf
, strlen(f
));
97 lxc_monitor_send_state(name
, freeze
? FROZEN
: THAWED
, lxcpath
);
103 ret
= lseek(fd
, 0L, SEEK_SET
);
105 SYSERROR("failed to lseek on file '%s'", freezer
);
109 ret
= write(fd
, f
, strlen(f
) + 1);
111 SYSERROR("failed to write '%s' to '%s'", f
, freezer
);
121 static int freeze_unfreeze(const char *name
, int freeze
, const char *lxcpath
)
126 cgabspath
= lxc_cgroup_path_get("freezer", name
, lxcpath
);
130 ret
= do_unfreeze(cgabspath
, freeze
, name
, lxcpath
);
135 int lxc_freeze(const char *name
, const char *lxcpath
)
137 lxc_monitor_send_state(name
, FREEZING
, lxcpath
);
138 return freeze_unfreeze(name
, 1, lxcpath
);
141 int lxc_unfreeze(const char *name
, const char *lxcpath
)
143 return freeze_unfreeze(name
, 0, lxcpath
);
146 int lxc_unfreeze_bypath(const char *cgrelpath
)
148 char cgabspath
[MAXPATHLEN
];
151 if (!get_subsys_mount(cgabspath
, "freezer"))
153 len
= strlen(cgabspath
);
154 ret
= snprintf(cgabspath
+len
, MAXPATHLEN
-len
, "/%s", cgrelpath
);
155 if (ret
< 0 || ret
>= MAXPATHLEN
-len
) {
156 ERROR("freezer path name too long");
160 return do_unfreeze(cgabspath
, 0, NULL
, NULL
);