]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/tools/lxc_wait.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
11 #include <sys/types.h>
16 #include "arguments.h"
20 lxc_log_define(lxc_wait
, lxc
);
22 static int my_parser(struct lxc_arguments
*args
, int c
, char *arg
);
23 static int my_checker(const struct lxc_arguments
*args
);
25 static const struct option my_longopts
[] = {
26 {"state", required_argument
, 0, 's'},
27 {"timeout", required_argument
, 0, 't'},
31 static struct lxc_arguments my_args
= {
32 .progname
= "lxc-wait",
34 --name=NAME --state=STATE\n\
36 lxc-wait waits for NAME container state to reach STATE\n\
39 -n, --name=NAME NAME of the container\n\
40 -s, --state=STATE ORed states to wait for\n\
41 STOPPED, STARTING, RUNNING, STOPPING,\n\
42 ABORTING, FREEZING, FROZEN, THAWED\n\
43 -t, --timeout=TMO Seconds to wait for state changes\n\
44 --rcfile=FILE Load configuration file FILE\n",
45 .options
= my_longopts
,
47 .checker
= my_checker
,
48 .log_priority
= "ERROR",
53 static int my_parser(struct lxc_arguments
*args
, int c
, char *arg
)
57 args
->states
= optarg
;
60 args
->timeout
= atol(optarg
);
67 static int my_checker(const struct lxc_arguments
*args
)
70 ERROR("Missing state option to wait for");
77 int main(int argc
, char *argv
[])
79 struct lxc_container
*c
;
82 if (lxc_arguments_parse(&my_args
, argc
, argv
))
85 log
.name
= my_args
.name
;
86 log
.file
= my_args
.log_file
;
87 log
.level
= my_args
.log_priority
;
88 log
.prefix
= my_args
.progname
;
89 log
.quiet
= my_args
.quiet
;
90 log
.lxcpath
= my_args
.lxcpath
[0];
92 if (lxc_log_init(&log
))
95 c
= lxc_container_new(my_args
.name
, my_args
.lxcpath
[0]);
99 if (!c
->may_control(c
)) {
100 ERROR("Insufficent privileges to control %s", c
->name
);
101 lxc_container_put(c
);
105 if (my_args
.rcfile
) {
108 if (!c
->load_config(c
, my_args
.rcfile
)) {
109 ERROR("Failed to load rcfile");
110 lxc_container_put(c
);
114 c
->configfile
= strdup(my_args
.rcfile
);
115 if (!c
->configfile
) {
116 ERROR("Out of memory setting new config filename");
117 lxc_container_put(c
);
122 if (!c
->wait(c
, my_args
.states
, my_args
.timeout
)) {
123 lxc_container_put(c
);