]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/lxc_checkpoint.c
2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2010
7 * Daniel Lezcano <dlezcano at fr.ibm.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include <sys/types.h>
35 #include <lxc/utils.h>
37 #include "arguments.h"
40 lxc_log_define(lxc_checkpoint_ui
, lxc_checkpoint
);
42 static int my_checker(const struct lxc_arguments
* args
)
44 if ((!args
->statefile
) && (args
->statefd
== -1)) {
45 lxc_error(args
, "no statefile specified");
49 if ((args
->statefile
) && (args
->statefd
!= -1)) {
50 lxc_error(args
, "--statefile AND --statefd abnormally set");
57 static int my_parser(struct lxc_arguments
* args
, int c
, char* arg
)
60 case 'k': args
->flags
= LXC_FLAG_HALT
; break;
61 case 'p': args
->flags
= LXC_FLAG_PAUSE
; break;
62 case 'S': args
->statefile
= arg
; break;
65 fd
= lxc_arguments_str_to_int(args
, arg
);
76 static const struct option my_longopts
[] = {
77 {"kill", no_argument
, 0, 'k'},
78 {"pause", no_argument
, 0, 'p'},
79 {"statefile", required_argument
, 0, 'S'},
80 {"statefd", required_argument
, 0, 'd'},
84 static struct lxc_arguments my_args
= {
85 .progname
= "lxc-checkpoint",
87 --name=NAME --statefile FILE\n\
89 lxc-checkpoint checkpoints in FILE the NAME container\n\
92 -n, --name=NAME NAME for name of the container\n\
93 -k, --kill stop the container after checkpoint\n\
94 -p, --pause don't unfreeze the container after the checkpoint\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",
98 .options
= my_longopts
,
100 .checker
= my_checker
,
105 int main(int argc
, char *argv
[])
110 ret
= lxc_arguments_parse(&my_args
, argc
, argv
);
114 ret
= lxc_log_init(my_args
.log_file
, my_args
.log_priority
,
115 my_args
.progname
, my_args
.quiet
);
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);
136 ERROR("failed to checkpoint '%s'", my_args
.name
);
138 INFO("'%s' checkpointed", my_args
.name
);
140 if (my_args
.statefile
)