]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/lxc_checkpoint.c
change C/R api
[mirror_lxc.git] / src / lxc / lxc_checkpoint.c
CommitLineData
925aaa31 1/*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
7 * Daniel Lezcano <dlezcano at fr.ibm.com>
8 *
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.
13 *
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.
18 *
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
22 */
3f8b55d5 23#define _GNU_SOURCE
925aaa31 24#include <stdio.h>
3f8b55d5 25#include <stdlib.h>
925aaa31 26#include <unistd.h>
ad3ac5e0
MN
27#include <errno.h>
28#include <sys/stat.h>
925aaa31 29#include <sys/types.h>
30
00b3c2e2
CLG
31#include <lxc/lxc.h>
32#include <lxc/log.h>
33#include <lxc/utils.h>
34
41cfbac9 35#include "arguments.h"
881450bb 36#include "config.h"
925aaa31 37
6b201d02
DL
38lxc_log_define(lxc_checkpoint, lxc);
39
41cfbac9 40static int my_checker(const struct lxc_arguments* args)
925aaa31 41{
6b201d02
DL
42 if (!args->statefile) {
43 lxc_error(args, "no statefile specified");
41cfbac9
MN
44 return -1;
45 }
6b201d02 46
41cfbac9 47 return 0;
925aaa31 48}
49
41cfbac9 50static int my_parser(struct lxc_arguments* args, int c, char* arg)
925aaa31 51{
41cfbac9 52 switch (c) {
ad3ac5e0
MN
53 case 'k': args->flags = LXC_FLAG_HALT; break;
54 case 'p': args->flags = LXC_FLAG_PAUSE; break;
6b201d02 55 case 'd': args->statefile = arg; break;
41cfbac9
MN
56 }
57 return 0;
58}
925aaa31 59
41cfbac9 60static const struct option my_longopts[] = {
3f739da8
DL
61 {"kill", no_argument, 0, 'k'},
62 {"pause", no_argument, 0, 'p'},
6b201d02 63 {"directory", required_argument, 0, 'd'},
41cfbac9
MN
64 LXC_COMMON_OPTIONS
65};
925aaa31 66
41cfbac9
MN
67static struct lxc_arguments my_args = {
68 .progname = "lxc-checkpoint",
69 .help = "\
47ad75f8 70--name=NAME --directory STATEFILE\n\
41cfbac9 71\n\
47ad75f8 72lxc-checkpoint checkpoints in STATEFILE the NAME container\n\
41cfbac9
MN
73\n\
74Options :\n\
75 -n, --name=NAME NAME for name of the container\n\
3f739da8 76 -k, --kill stop the container after checkpoint\n\
6b201d02 77 -p, --pause don't unfreeze the container after the checkpoint\n\
47ad75f8 78 -d, --directory=STATEFILE where to store the statefile\n",
3f739da8 79
41cfbac9
MN
80 .options = my_longopts,
81 .parser = my_parser,
82 .checker = my_checker,
925aaa31 83
41cfbac9
MN
84 .rcfile = NULL,
85};
925aaa31 86
ad3ac5e0 87static int create_statefile(const char *dir)
3f8b55d5 88{
ad3ac5e0
MN
89 if (mkdir(dir, 0700) == -1 && errno != EEXIST) {
90 ERROR("'%s' creation error : %m", dir);
3f8b55d5
DL
91 return -1;
92 }
93
ad3ac5e0 94 return 0;
3f8b55d5
DL
95}
96
41cfbac9
MN
97int main(int argc, char *argv[])
98{
ad3ac5e0 99 int ret;
41cfbac9 100
3f739da8
DL
101 ret = lxc_arguments_parse(&my_args, argc, argv);
102 if (ret)
a30284df 103 return ret;
f66af38b 104
3f739da8
DL
105 ret = lxc_log_init(my_args.log_file, my_args.log_priority,
106 my_args.progname, my_args.quiet);
107 if (ret)
a30284df 108 return ret;
51cab631 109
ad3ac5e0
MN
110 ret = create_statefile(my_args.statefile);
111 if (ret)
3f8b55d5 112 return ret;
3f8b55d5 113
ad3ac5e0 114 ret = lxc_checkpoint(my_args.name, my_args.statefile, my_args.flags);
6b201d02
DL
115 if (ret) {
116 ERROR("failed to checkpoint '%s'", my_args.name);
a30284df 117 return ret;
6b201d02
DL
118 }
119
120 INFO("'%s' checkpointed", my_args.name);
893c6f54 121
893c6f54 122 return ret;
925aaa31 123}