40
42
static int my_checker(const struct lxc_arguments* args)
42
if (!args->statefile) {
44
if ((!args->statefile) && (args->statefd == -1)) {
43
45
lxc_error(args, "no statefile specified");
49
if ((args->statefile) && (args->statefd != -1)) {
50
lxc_error(args, "--statefile AND --statefd abnormally set");
53
60
case 'k': args->flags = LXC_FLAG_HALT; break;
54
61
case 'p': args->flags = LXC_FLAG_PAUSE; break;
55
case 'd': args->statefile = arg; break;
62
case 'S': args->statefile = arg; break;
65
fd = lxc_arguments_str_to_int(args, arg);
60
76
static const struct option my_longopts[] = {
61
77
{"kill", no_argument, 0, 'k'},
62
78
{"pause", no_argument, 0, 'p'},
63
{"directory", required_argument, 0, 'd'},
79
{"statefile", required_argument, 0, 'S'},
80
{"statefd", required_argument, 0, 'd'},
67
84
static struct lxc_arguments my_args = {
68
85
.progname = "lxc-checkpoint",
70
--name=NAME --directory STATEFILE\n\
87
--name=NAME --statefile FILE\n\
72
lxc-checkpoint checkpoints in STATEFILE the NAME container\n\
89
lxc-checkpoint checkpoints in FILE the NAME container\n\
75
92
-n, --name=NAME NAME for name of the container\n\
76
93
-k, --kill stop the container after checkpoint\n\
77
94
-p, --pause don't unfreeze the container after the checkpoint\n\
78
-d, --directory=STATEFILE where to store the statefile\n",
95
-S, --statefile=FILE write the container state into this file, or\n\
96
-d, --statefd=FD write the container state into this file descriptor\n",
80
98
.options = my_longopts,
81
99
.parser = my_parser,
82
100
.checker = my_checker,
87
static int create_statefile(const char *dir)
89
if (mkdir(dir, 0700) == -1 && errno != EEXIST) {
90
ERROR("'%s' creation error : %m", dir);
97
105
int main(int argc, char *argv[])
101
110
ret = lxc_arguments_parse(&my_args, argc, argv);
110
ret = create_statefile(my_args.statefile);
114
ret = lxc_checkpoint(my_args.name, my_args.statefile, my_args.flags);
119
if (my_args.statefd != -1)
120
sfd = my_args.statefd;
122
#define OPEN_WRITE_MODE O_CREAT | O_RDWR | O_EXCL | O_CLOEXEC | O_LARGEFILE
123
if (my_args.statefile) {
124
sfd = open(my_args.statefile, OPEN_WRITE_MODE, 0600);
126
ERROR("'%s' open failure : %m", my_args.statefile);
131
ret = lxc_checkpoint(my_args.name, sfd, my_args.flags);
133
assert(ret == 0 || ret == -1);
116
136
ERROR("failed to checkpoint '%s'", my_args.name);
118
138
INFO("'%s' checkpointed", my_args.name);
140
if (my_args.statefile)