lxc_log_define(lxc_checkpoint, lxc);
-int lxc_checkpoint(const char *name, const char *statefile, int flags)
+int lxc_checkpoint(const char *name, int sfd, int flags)
{
- return 0;
+ ERROR("'checkpoint' function not implemented");
+ return -1;
}
/*
* Checkpoint a container
* @name : the name of the container being checkpointed
- * @statefile: string object on which the container is checkpointed
+ * @sfd: fd on which the container is checkpointed
* @flags : checkpoint flags (an ORed value)
* Returns 0 on success, < 0 otherwise
*/
-extern int lxc_checkpoint(const char *name, const char *statefile, int flags);
+extern int lxc_checkpoint(const char *name, int sfd, int flags);
#define LXC_FLAG_PAUSE 1
#define LXC_FLAG_HALT 2
/*
* Restart a container
* @name : the name of the container being restarted
- * @statefile: string object from which the container is restarted
+ * @sfd: fd from which the container is restarted
* @conf: lxc_conf structure.
* @flags : restart flags (an ORed value)
* Returns 0 on success, < 0 otherwise
*/
-extern int lxc_restart(const char *, const char *, struct lxc_conf *, int);
+extern int lxc_restart(const char *, int, struct lxc_conf *, int);
/*
* Returns the version number of the library
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <fcntl.h>
#include <lxc/lxc.h>
#include <lxc/log.h>
switch (c) {
case 'k': args->flags = LXC_FLAG_HALT; break;
case 'p': args->flags = LXC_FLAG_PAUSE; break;
- case 'd': args->statefile = arg; break;
+ case 'S': args->statefile = arg; break;
}
return 0;
}
static const struct option my_longopts[] = {
{"kill", no_argument, 0, 'k'},
{"pause", no_argument, 0, 'p'},
- {"directory", required_argument, 0, 'd'},
+ {"statefile", required_argument, 0, 'S'},
LXC_COMMON_OPTIONS
};
static struct lxc_arguments my_args = {
.progname = "lxc-checkpoint",
.help = "\
---name=NAME --directory STATEFILE\n\
+--name=NAME --statefile STATEFILE\n\
\n\
lxc-checkpoint checkpoints in STATEFILE the NAME container\n\
\n\
-n, --name=NAME NAME for name of the container\n\
-k, --kill stop the container after checkpoint\n\
-p, --pause don't unfreeze the container after the checkpoint\n\
- -d, --directory=STATEFILE where to store the statefile\n",
+ -S, --statefile=STATEFILE file in which to store the statefile\n",
.options = my_longopts,
.parser = my_parser,
.rcfile = NULL,
};
-static int create_statefile(const char *dir)
-{
- if (mkdir(dir, 0700) == -1 && errno != EEXIST) {
- ERROR("'%s' creation error : %m", dir);
- return -1;
- }
-
- return 0;
-}
-
int main(int argc, char *argv[])
{
int ret;
+ int sfd = -1;
ret = lxc_arguments_parse(&my_args, argc, argv);
if (ret)
if (ret)
return ret;
- ret = create_statefile(my_args.statefile);
- if (ret)
- return ret;
+#define OPEN_WRITE_MODE O_CREAT | O_RDWR | O_EXCL | O_CLOEXEC | O_LARGEFILE
+ sfd = open(my_args.statefile, OPEN_WRITE_MODE, 0600);
+ if (sfd < 0) {
+ ERROR("'%s' open failure : %m", my_args.statefile);
+ return sfd;
+ }
- ret = lxc_checkpoint(my_args.name, my_args.statefile, my_args.flags);
+ ret = lxc_checkpoint(my_args.name, sfd, my_args.flags);
if (ret)
ERROR("failed to checkpoint '%s'", my_args.name);
else
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
+#include <fcntl.h>
#include "log.h"
#include "lxc.h"
static int my_parser(struct lxc_arguments* args, int c, char* arg)
{
switch (c) {
- case 'd': args->statefile = arg; break;
+ case 'S': args->statefile = arg; break;
case 'f': args->rcfile = arg; break;
case 'p': args->flags = LXC_FLAG_PAUSE; break;
case 's': return lxc_config_define_add(&defines, arg);
}
static const struct option my_longopts[] = {
- {"directory", required_argument, 0, 'd'},
+ {"statefile", required_argument, 0, 'S'},
{"rcfile", required_argument, 0, 'f'},
{"pause", no_argument, 0, 'p'},
{"define", required_argument, 0, 's'},
static struct lxc_arguments my_args = {
.progname = "lxc-restart",
.help = "\
---name=NAME --directory STATEFILE\n\
+--name=NAME --statefile STATEFILE\n\
\n\
lxc-restart restarts from STATEFILE the NAME container\n\
\n\
Options :\n\
-n, --name=NAME NAME for name of the container\n\
-p, --pause do not release the container after the restart\n\
- -d, --directory=STATEFILE for name of statefile\n\
+ -S, --statefile=STATEFILE file from which to read data\n\
-f, --rcfile=FILE Load configuration file FILE\n\
-s, --define KEY=VAL Assign VAL to configuration variable KEY\n",
.options = my_longopts,
int main(int argc, char *argv[])
{
+ int sfd = -1;
char *rcfile = NULL;
struct lxc_conf *conf;
if (lxc_config_define_load(&defines, conf))
return -1;
- return lxc_restart(my_args.name, my_args.statefile, conf,
- my_args.flags);
+#define OPEN_READ_MODE O_RDONLY | O_CLOEXEC | O_LARGEFILE
+ sfd = open(my_args.statefile, OPEN_READ_MODE, 0);
+ if (sfd < 0) {
+ ERROR("'%s' open failure : %m", my_args.statefile);
+ return sfd;
+ }
+
+ return lxc_restart(my_args.name, sfd, conf, my_args.flags);
}
lxc_log_define(lxc_restart, lxc);
-int lxc_restart(const char *name, const char *statefile, struct lxc_conf *conf,
- int flags)
+int lxc_restart(const char *name, int sfd, struct lxc_conf *conf, int flags)
{
- return 0;
+ ERROR("'restart' function not implemented");
+ return -1;
}