]>
Commit | Line | Data |
---|---|---|
5e97c3fc | 1 | /* |
2 | * lxc: linux Container library | |
3 | * | |
4 | * (C) Copyright IBM Corp. 2007, 2008 | |
5 | * | |
6 | * Authors: | |
9afe19d6 | 7 | * Daniel Lezcano <daniel.lezcano at free.fr> |
5e97c3fc | 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 | |
250b1eec | 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
5e97c3fc | 22 | */ |
23 | #include <stdio.h> | |
24 | #include <unistd.h> | |
25 | #include <libgen.h> | |
26 | #include <sys/types.h> | |
27 | ||
92b0b5ba | 28 | #include <lxc/lxccontainer.h> |
00b3c2e2 | 29 | |
f2363e38 ÇO |
30 | #include "lxc.h" |
31 | #include "log.h" | |
4237c6ca | 32 | #include "arguments.h" |
5e97c3fc | 33 | |
6ea518f6 | 34 | lxc_log_define(lxc_unfreeze_ui, lxc); |
92b0b5ba | 35 | |
4237c6ca MN |
36 | static const struct option my_longopts[] = { |
37 | LXC_COMMON_OPTIONS | |
38 | }; | |
39 | ||
40 | static struct lxc_arguments my_args = { | |
41 | .progname = "lxc-unfreeze", | |
42 | .help = "\ | |
43 | --name=NAME\n\ | |
44 | \n\ | |
45 | lxc-unfreeze unfreezes a container with the identifier NAME\n\ | |
46 | \n\ | |
47 | Options :\n\ | |
50b737a3 WB |
48 | -n, --name=NAME NAME of the container\n\ |
49 | --rcfile=FILE Load configuration file FILE\n", | |
4237c6ca MN |
50 | .options = my_longopts, |
51 | .parser = NULL, | |
52 | .checker = NULL, | |
53 | }; | |
5e97c3fc | 54 | |
55 | int main(int argc, char *argv[]) | |
56 | { | |
92b0b5ba | 57 | struct lxc_container *c; |
73b910a3 | 58 | struct lxc_log log; |
92b0b5ba | 59 | |
c8f55b0e | 60 | if (lxc_arguments_parse(&my_args, argc, argv)) |
b52b0595 | 61 | exit(EXIT_FAILURE); |
5e97c3fc | 62 | |
f5abd74d SG |
63 | if (!my_args.log_file) |
64 | my_args.log_file = "none"; | |
65 | ||
73b910a3 | 66 | log.name = my_args.name; |
67 | log.file = my_args.log_file; | |
4b73005c | 68 | log.level = my_args.log_priority; |
73b910a3 | 69 | log.prefix = my_args.progname; |
70 | log.quiet = my_args.quiet; | |
71 | log.lxcpath = my_args.lxcpath[0]; | |
72 | ||
73 | ||
74 | if (lxc_log_init(&log)) | |
b52b0595 | 75 | exit(EXIT_FAILURE); |
6edbfc86 | 76 | lxc_log_options_no_override(); |
5e97c3fc | 77 | |
92b0b5ba SH |
78 | c = lxc_container_new(my_args.name, my_args.lxcpath[0]); |
79 | if (!c) { | |
80 | ERROR("No such container: %s:%s", my_args.lxcpath[0], my_args.name); | |
b52b0595 | 81 | exit(EXIT_FAILURE); |
92b0b5ba | 82 | } |
5e97c3fc | 83 | |
f5abd74d SG |
84 | if (!c->may_control(c)) { |
85 | ERROR("Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name); | |
f3e52710 | 86 | lxc_container_put(c); |
b52b0595 | 87 | exit(EXIT_FAILURE); |
f5abd74d SG |
88 | } |
89 | ||
50b737a3 WB |
90 | if (my_args.rcfile) { |
91 | c->clear_config(c); | |
92 | if (!c->load_config(c, my_args.rcfile)) { | |
93 | ERROR("Failed to load rcfile"); | |
94 | lxc_container_put(c); | |
b52b0595 | 95 | exit(EXIT_FAILURE); |
50b737a3 | 96 | } |
6118210e WB |
97 | c->configfile = strdup(my_args.rcfile); |
98 | if (!c->configfile) { | |
99 | ERROR("Out of memory setting new config filename"); | |
100 | lxc_container_put(c); | |
b52b0595 | 101 | exit(EXIT_FAILURE); |
6118210e | 102 | } |
50b737a3 WB |
103 | } |
104 | ||
92b0b5ba SH |
105 | if (!c->unfreeze(c)) { |
106 | ERROR("Failed to unfreeze %s:%s", my_args.lxcpath[0], my_args.name); | |
107 | lxc_container_put(c); | |
b52b0595 | 108 | exit(EXIT_FAILURE); |
92b0b5ba SH |
109 | } |
110 | ||
111 | lxc_container_put(c); | |
112 | ||
b52b0595 | 113 | exit(EXIT_SUCCESS); |
92b0b5ba | 114 | } |