42
43
static int my_checker(const struct lxc_arguments* args)
44
if (!args->statefile) {
45
if ((!args->statefile) && (args->statefd == -1)) {
45
46
lxc_error(args, "no statefile specified");
50
if ((args->statefile) && (args->statefd != -1)) {
51
lxc_error(args, "--statefile AND --statefd abnormally set");
52
58
static int my_parser(struct lxc_arguments* args, int c, char* arg)
55
case 'd': args->statefile = arg; break;
61
case 'S': args->statefile = arg; break;
56
62
case 'f': args->rcfile = arg; break;
57
63
case 'p': args->flags = LXC_FLAG_PAUSE; break;
58
64
case 's': return lxc_config_define_add(&defines, arg);
67
fd = lxc_arguments_str_to_int(args, arg);
64
79
static const struct option my_longopts[] = {
65
{"directory", required_argument, 0, 'd'},
80
{"statefile", required_argument, 0, 'S'},
81
{"statefd", required_argument, 0, 'd'},
66
82
{"rcfile", required_argument, 0, 'f'},
67
83
{"pause", no_argument, 0, 'p'},
68
84
{"define", required_argument, 0, 's'},
72
88
static struct lxc_arguments my_args = {
73
89
.progname = "lxc-restart",
75
--name=NAME --directory STATEFILE\n\
91
--name=NAME --statefile FILE\n\
77
lxc-restart restarts from STATEFILE the NAME container\n\
93
lxc-restart restarts from FILE the NAME container\n\
80
96
-n, --name=NAME NAME for name of the container\n\
81
-p, --pause do not release the container after the restart\n\
82
-d, --directory=STATEFILE for name of statefile\n\
97
-p, --pause do not unfreeze the container after the restart\n\
98
-S, --statefile=FILE read the container state from this file, or\n\
99
-d, --statefd=FD read the container state from this file descriptor\n\
83
100
-f, --rcfile=FILE Load configuration file FILE\n\
84
101
-s, --define KEY=VAL Assign VAL to configuration variable KEY\n",
85
102
.options = my_longopts,
86
103
.parser = my_parser,
87
104
.checker = my_checker,
90
109
int main(int argc, char *argv[])
92
113
char *rcfile = NULL;
93
114
struct lxc_conf *conf;
105
126
if (my_args.rcfile)
106
127
rcfile = (char *)my_args.rcfile;
108
if (!asprintf(&rcfile, LXCPATH "/%s/config", my_args.name)) {
131
rc = asprintf(&rcfile, LXCPATH "/%s/config", my_args.name);
109
133
SYSERROR("failed to allocate memory");
131
155
if (lxc_config_define_load(&defines, conf))
134
return lxc_restart(my_args.name, my_args.statefile, conf,
158
if (my_args.statefd != -1)
159
sfd = my_args.statefd;
161
#define OPEN_READ_MODE O_RDONLY | O_CLOEXEC | O_LARGEFILE
162
if (my_args.statefile) {
163
sfd = open(my_args.statefile, OPEN_READ_MODE, 0);
165
ERROR("'%s' open failure : %m", my_args.statefile);
170
ret = lxc_restart(my_args.name, sfd, conf, my_args.flags);
172
if (my_args.statefile)