]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/tools/lxc_freeze.c
tools: move --rcfile to the common options list
[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 lxc_log_define(lxc_freeze_ui, lxc);
37
38 static const struct option my_longopts[] = {
39 LXC_COMMON_OPTIONS
40 };
41
42 static struct lxc_arguments my_args = {
43 .progname = "lxc-freeze",
44 .help = "\
45 --name=NAME\n\
46 \n\
47 lxc-freeze freezes a container with the identifier NAME\n\
48 \n\
49 Options :\n\
50 -n, --name=NAME NAME of the container\n\
51 --rcfile=FILE Load configuration file FILE\n",
52 .options = my_longopts,
53 .parser = NULL,
54 .checker = NULL,
55 };
56
57 int main(int argc, char *argv[])
58 {
59 struct lxc_container *c;
60
61 if (lxc_arguments_parse(&my_args, argc, argv))
62 exit(1);
63
64 if (!my_args.log_file)
65 my_args.log_file = "none";
66
67 if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
68 my_args.progname, my_args.quiet, my_args.lxcpath[0]))
69 exit(1);
70 lxc_log_options_no_override();
71
72 c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
73 if (!c) {
74 ERROR("No such container: %s:%s", my_args.lxcpath[0], my_args.name);
75 exit(1);
76 }
77
78 if (my_args.rcfile) {
79 c->clear_config(c);
80 if (!c->load_config(c, my_args.rcfile)) {
81 ERROR("Failed to load rcfile");
82 lxc_container_put(c);
83 exit(1);
84 }
85 }
86
87 if (!c->may_control(c)) {
88 ERROR("Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
89 lxc_container_put(c);
90 exit(1);
91 }
92
93 if (!c->freeze(c)) {
94 ERROR("Failed to freeze %s:%s", my_args.lxcpath[0], my_args.name);
95 lxc_container_put(c);
96 exit(1);
97 }
98
99 lxc_container_put(c);
100
101 exit(0);
102 }