]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/tools/lxc_freeze.c
Merge pull request #1932 from 3XX0/dhclient-hook
[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 #include <stdio.h>
24 #include <unistd.h>
25 #include <sys/types.h>
26 #include <libgen.h>
27 #include <string.h>
28
29 #include <lxc/lxccontainer.h>
30
31 #include "lxc.h"
32 #include "log.h"
33
34 #include "arguments.h"
35
36 static const struct option my_longopts[] = {
37 LXC_COMMON_OPTIONS
38 };
39
40 static struct lxc_arguments my_args = {
41 .progname = "lxc-freeze",
42 .help = "\
43 --name=NAME\n\
44 \n\
45 lxc-freeze freezes a container with the identifier NAME\n\
46 \n\
47 Options :\n\
48 -n, --name=NAME NAME of the container\n\
49 --rcfile=FILE Load configuration file FILE\n",
50 .options = my_longopts,
51 .parser = NULL,
52 .checker = NULL,
53 };
54
55 int main(int argc, char *argv[])
56 {
57 struct lxc_container *c;
58 struct lxc_log log;
59
60 if (lxc_arguments_parse(&my_args, argc, argv))
61 exit(EXIT_FAILURE);
62
63 if (!my_args.log_file)
64 my_args.log_file = "none";
65
66 log.name = my_args.name;
67 log.file = my_args.log_file;
68 log.level = my_args.log_priority;
69 log.prefix = my_args.progname;
70 log.quiet = my_args.quiet;
71 log.lxcpath = my_args.lxcpath[0];
72
73 if (lxc_log_init(&log))
74 exit(EXIT_FAILURE);
75 lxc_log_options_no_override();
76
77 /* REMOVE IN LXC 3.0 */
78 setenv("LXC_UPDATE_CONFIG_FORMAT", "1", 0);
79
80 c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
81 if (!c) {
82 fprintf(stderr, "No such container: %s:%s\n", my_args.lxcpath[0], my_args.name);
83 exit(EXIT_FAILURE);
84 }
85
86 if (my_args.rcfile) {
87 c->clear_config(c);
88 if (!c->load_config(c, my_args.rcfile)) {
89 fprintf(stderr, "Failed to load rcfile\n");
90 lxc_container_put(c);
91 exit(EXIT_FAILURE);
92 }
93 c->configfile = strdup(my_args.rcfile);
94 if (!c->configfile) {
95 fprintf(stderr, "Out of memory setting new config filename\n");
96 lxc_container_put(c);
97 exit(EXIT_FAILURE);
98 }
99 }
100
101 if (!c->may_control(c)) {
102 fprintf(stderr, "Insufficent privileges to control %s:%s\n", my_args.lxcpath[0], my_args.name);
103 lxc_container_put(c);
104 exit(EXIT_FAILURE);
105 }
106
107 if (!c->freeze(c)) {
108 fprintf(stderr, "Failed to freeze %s:%s\n", my_args.lxcpath[0], my_args.name);
109 lxc_container_put(c);
110 exit(EXIT_FAILURE);
111 }
112
113 lxc_container_put(c);
114
115 exit(EXIT_SUCCESS);
116 }