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