]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/tools/lxc_freeze.c
API: expose function lxc_log_init
[mirror_lxc.git] / src / lxc / tools / lxc_freeze.c
CommitLineData
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 <sys/types.h>
26#include <libgen.h>
27#include <string.h>
28
92b0b5ba 29#include <lxc/lxccontainer.h>
00b3c2e2 30
f2363e38
ÇO
31#include "lxc.h"
32#include "log.h"
33
4237c6ca 34#include "arguments.h"
5e97c3fc 35
6ea518f6 36lxc_log_define(lxc_freeze_ui, lxc);
92b0b5ba 37
4237c6ca
MN
38static const struct option my_longopts[] = {
39 LXC_COMMON_OPTIONS
40};
41
42static struct lxc_arguments my_args = {
43 .progname = "lxc-freeze",
44 .help = "\
45--name=NAME\n\
46\n\
47lxc-freeze freezes a container with the identifier NAME\n\
48\n\
49Options :\n\
50b737a3
WB
50 -n, --name=NAME NAME of the container\n\
51 --rcfile=FILE Load configuration file FILE\n",
4237c6ca
MN
52 .options = my_longopts,
53 .parser = NULL,
54 .checker = NULL,
55};
5e97c3fc 56
57int main(int argc, char *argv[])
58{
92b0b5ba 59 struct lxc_container *c;
73b910a3 60 struct lxc_log log;
92b0b5ba 61
c8f55b0e 62 if (lxc_arguments_parse(&my_args, argc, argv))
b52b0595 63 exit(EXIT_FAILURE);
5e97c3fc 64
f5abd74d
SG
65 if (!my_args.log_file)
66 my_args.log_file = "none";
67
73b910a3 68 log.name = my_args.name;
69 log.file = my_args.log_file;
70 log.priority = my_args.log_priority;
71 log.prefix = my_args.progname;
72 log.quiet = my_args.quiet;
73 log.lxcpath = my_args.lxcpath[0];
74
75 if (lxc_log_init(&log))
b52b0595 76 exit(EXIT_FAILURE);
6edbfc86 77 lxc_log_options_no_override();
5e97c3fc 78
92b0b5ba
SH
79 c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
80 if (!c) {
81 ERROR("No such container: %s:%s", my_args.lxcpath[0], my_args.name);
b52b0595 82 exit(EXIT_FAILURE);
92b0b5ba 83 }
5e97c3fc 84
50b737a3
WB
85 if (my_args.rcfile) {
86 c->clear_config(c);
87 if (!c->load_config(c, my_args.rcfile)) {
88 ERROR("Failed to load rcfile");
89 lxc_container_put(c);
b52b0595 90 exit(EXIT_FAILURE);
50b737a3 91 }
6118210e
WB
92 c->configfile = strdup(my_args.rcfile);
93 if (!c->configfile) {
94 ERROR("Out of memory setting new config filename");
95 lxc_container_put(c);
b52b0595 96 exit(EXIT_FAILURE);
6118210e 97 }
50b737a3
WB
98 }
99
f5abd74d
SG
100 if (!c->may_control(c)) {
101 ERROR("Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
f3e52710 102 lxc_container_put(c);
b52b0595 103 exit(EXIT_FAILURE);
f5abd74d
SG
104 }
105
92b0b5ba
SH
106 if (!c->freeze(c)) {
107 ERROR("Failed to freeze %s:%s", my_args.lxcpath[0], my_args.name);
108 lxc_container_put(c);
b52b0595 109 exit(EXIT_FAILURE);
92b0b5ba
SH
110 }
111
112 lxc_container_put(c);
113
b52b0595 114 exit(EXIT_SUCCESS);
92b0b5ba 115}