]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/tools/lxc_unfreeze.c
tree-wide: fix lxc header inclusion
[mirror_lxc.git] / src / lxc / tools / lxc_unfreeze.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #ifndef _GNU_SOURCE
4 #define _GNU_SOURCE 1
5 #endif
6 #include <libgen.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <sys/types.h>
10 #include <unistd.h>
11
12 #include "lxc.h"
13
14 #include "arguments.h"
15 #include "config.h"
16 #include "log.h"
17
18 lxc_log_define(lxc_unfreeze, lxc);
19
20 static const struct option my_longopts[] = {
21 LXC_COMMON_OPTIONS
22 };
23
24 static struct lxc_arguments my_args = {
25 .progname = "lxc-unfreeze",
26 .help = "\
27 --name=NAME\n\
28 \n\
29 lxc-unfreeze unfreezes a container with the identifier NAME\n\
30 \n\
31 Options :\n\
32 -n, --name=NAME NAME of the container\n\
33 --rcfile=FILE Load configuration file FILE\n",
34 .options = my_longopts,
35 .parser = NULL,
36 .checker = NULL,
37 .log_priority = "ERROR",
38 .log_file = "none",
39 };
40
41 int main(int argc, char *argv[])
42 {
43 struct lxc_container *c;
44 struct lxc_log log;
45
46 if (lxc_arguments_parse(&my_args, argc, argv))
47 exit(EXIT_FAILURE);
48
49 log.name = my_args.name;
50 log.file = my_args.log_file;
51 log.level = my_args.log_priority;
52 log.prefix = my_args.progname;
53 log.quiet = my_args.quiet;
54 log.lxcpath = my_args.lxcpath[0];
55
56 if (lxc_log_init(&log))
57 exit(EXIT_FAILURE);
58
59 c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
60 if (!c) {
61 ERROR("No such container: %s:%s", my_args.lxcpath[0], my_args.name);
62 exit(EXIT_FAILURE);
63 }
64
65 if (!c->may_control(c)) {
66 ERROR("Insufficent privileges to control %s:%s", my_args.lxcpath[0], my_args.name);
67 lxc_container_put(c);
68 exit(EXIT_FAILURE);
69 }
70
71 if (my_args.rcfile) {
72 c->clear_config(c);
73
74 if (!c->load_config(c, my_args.rcfile)) {
75 ERROR("Failed to load rcfile");
76 lxc_container_put(c);
77 exit(EXIT_FAILURE);
78 }
79
80 c->configfile = strdup(my_args.rcfile);
81 if (!c->configfile) {
82 ERROR("Out of memory setting new config filename");
83 lxc_container_put(c);
84 exit(EXIT_FAILURE);
85 }
86 }
87
88 if (!c->unfreeze(c)) {
89 ERROR("Failed to unfreeze %s:%s", my_args.lxcpath[0], my_args.name);
90 lxc_container_put(c);
91 exit(EXIT_FAILURE);
92 }
93
94 lxc_container_put(c);
95
96 exit(EXIT_SUCCESS);
97 }