]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/tools/lxc_freeze.c
Merge pull request #2652 from brauner/lxc/master
[mirror_lxc.git] / src / lxc / tools / lxc_freeze.c
1 /*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
7 * Daniel Lezcano <daniel.lezcano at free.fr>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #ifndef _GNU_SOURCE
25 #define _GNU_SOURCE 1
26 #endif
27 #include <libgen.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <sys/types.h>
31 #include <unistd.h>
32
33 #include <lxc/lxccontainer.h>
34
35 #include "arguments.h"
36 #include "config.h"
37 #include "log.h"
38
39 lxc_log_define(lxc_freeze, lxc);
40
41 static const struct option my_longopts[] = {
42 LXC_COMMON_OPTIONS
43 };
44
45 static struct lxc_arguments my_args = {
46 .progname = "lxc-freeze",
47 .help = "\
48 --name=NAME\n\
49 \n\
50 lxc-freeze freezes a container with the identifier NAME\n\
51 \n\
52 Options :\n\
53 -n, --name=NAME NAME of the container\n\
54 --rcfile=FILE Load configuration file FILE\n",
55 .options = my_longopts,
56 .parser = NULL,
57 .checker = NULL,
58 .log_priority = "ERROR",
59 .log_file = "none",
60 };
61
62 int main(int argc, char *argv[])
63 {
64 struct lxc_container *c;
65 struct lxc_log log;
66
67 if (lxc_arguments_parse(&my_args, argc, argv))
68 exit(EXIT_FAILURE);
69
70 log.name = my_args.name;
71 log.file = my_args.log_file;
72 log.level = my_args.log_priority;
73 log.prefix = my_args.progname;
74 log.quiet = my_args.quiet;
75 log.lxcpath = my_args.lxcpath[0];
76
77 if (lxc_log_init(&log))
78 exit(EXIT_FAILURE);
79
80 c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
81 if (!c) {
82 ERROR("No such container: %s:%s", my_args.lxcpath[0], my_args.name);
83 exit(EXIT_FAILURE);
84 }
85
86 if (my_args.rcfile) {
87 c->clear_config(c);
88
89 if (!c->load_config(c, my_args.rcfile)) {
90 ERROR("Failed to load rcfile");
91 lxc_container_put(c);
92 exit(EXIT_FAILURE);
93 }
94
95 c->configfile = strdup(my_args.rcfile);
96 if (!c->configfile) {
97 ERROR("Out of memory setting new config filename");
98 lxc_container_put(c);
99 exit(EXIT_FAILURE);
100 }
101 }
102
103 if (!c->may_control(c)) {
104 ERROR("Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
105 lxc_container_put(c);
106 exit(EXIT_FAILURE);
107 }
108
109 if (!c->freeze(c)) {
110 ERROR("Failed to freeze %s:%s", my_args.lxcpath[0], my_args.name);
111 lxc_container_put(c);
112 exit(EXIT_FAILURE);
113 }
114
115 lxc_container_put(c);
116
117 exit(EXIT_SUCCESS);
118 }