version.c \
error.h error.c \
cgroup.c cgroup.h \
+ cr_plugin_columbia.c \
lxc.h \
lxc_utils.h \
lxc_lock.c lxc_lock.h \
#include <net/if.h>
#include "error.h"
+#include "lxc_plugin.h"
#include <lxc.h>
#define MAXPIDLEN 20
-#if __i386__
-# define __NR_checkpoint 333
-static inline long sys_checkpoint(pid_t pid, int fd, unsigned long flags)
-{
- return syscall(__NR_checkpoint, pid, fd, flags);
-}
-#elif __x86_64__
-# define __NR_checkpoint 295
-static inline long sys_checkpoint(pid_t pid, int fd, unsigned long flags)
-{
- return syscall(__NR_checkpoint, pid, fd, flags);
-}
-#else
-# warning "Architecture not supported for checkpoint"
-static inline long sys_checkpoint(pid_t pid, int fd, unsigned long flags)
-{
- errno = ENOSYS;
- return -1;
-}
-
-#endif
-
-int lxc_checkpoint(const char *name, int cfd, unsigned long flags)
+int lxc_checkpoint(const char *name, const char *statefile,
+ unsigned long flags)
{
char init[MAXPATHLEN];
char val[MAXPIDLEN];
pid = atoi(val);
- if (sys_checkpoint(pid, cfd, flags) < 0) {
+ if (lxc_plugin_checkpoint(pid, statefile, flags) < 0) {
lxc_log_syserror("failed to checkpoint %zd", pid);
goto out_close;
}
--- /dev/null
+/*
+ * lxc: linux Container library
+ *
+ * (C) Copyright IBM Corp. 2007, 2008
+ *
+ * Authors:
+ * Daniel Lezcano <dlezcano at fr.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#define _GNU_SOURCE
+#include <stdio.h>
+#undef _GNU_SOURCE
+#include <fcntl.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <sys/file.h>
+
+#include "error.h"
+#include <lxc.h>
+
+#if __i386__
+# define __NR_checkpoint 333
+# define __NR_restart 334
+static inline long sys_checkpoint(pid_t pid, int fd, unsigned long flags)
+{
+ return syscall(__NR_checkpoint, pid, fd, flags);
+}
+static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
+{
+ return syscall(__NR_restart, pid, fd, flags);
+}
+#elif __x86_64__
+# define __NR_checkpoint 295
+# define __NR_restart 296
+static inline long sys_checkpoint(pid_t pid, int fd, unsigned long flags)
+{
+ return syscall(__NR_checkpoint, pid, fd, flags);
+}
+static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
+{
+ return syscall(__NR_restart, pid, fd, flags);
+}
+#else
+# warning "Architecture not supported for checkpoint"
+static inline long sys_checkpoint(pid_t pid, int fd, unsigned long flags)
+{
+ errno = ENOSYS;
+ return -1;
+}
+static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
+{
+ errno = ENOSYS;
+ return -1;
+}
+# warning "Architecture not supported for restart syscall"
+
+#endif
+
+
+int lxc_plugin_checkpoint(pid_t pid, const char *statefile,
+ unsigned long flags)
+{
+ int fd, ret;
+
+ fd = open(statefile, O_RDWR);
+ if (fd < 0) {
+ lxc_log_syserror("failed to open init file for %s", statefile);
+ return -1;
+ }
+
+ ret = sys_checkpoint(pid, fd, flags);
+ if (ret < 0) {
+ lxc_log_syserror("failed to checkpoint %zd", pid);
+ goto out_close;
+ }
+
+ ret = 0;
+
+out_close:
+ close(fd);
+ return ret;
+}
+
+int lxc_plugin_restart(pid_t pid, const char *statefile,
+ unsigned long flags)
+{
+ int fd;
+
+ fd = open(statefile, O_RDONLY);
+ if (fd < 0) {
+ lxc_log_syserror("failed to open init file for %s", statefile);
+ return -1;
+ }
+
+ sys_restart(pid, fd, flags);
+ lxc_log_syserror("failed to restart %zd", pid);
+ close(fd);
+ return -1;
+}
* @flags : checkpoint flags
* Returns 0 on success, < 0 otherwise
*/
-extern int lxc_checkpoint(const char *name, int fd, unsigned long flags);
+extern int lxc_checkpoint(const char *name, const char *statefile,
+ unsigned long flags);
/*
* Restart a container previously frozen
* @flags : restart flags
* Returns 0 on success, < 0 otherwise
*/
-extern int lxc_restart(const char *name, int fd, unsigned long flags);
+extern int lxc_restart(const char *name, const char *statefile,
+ unsigned long flags);
/*
* Returns the version number of the library
void usage(char *cmd)
{
- fprintf(stderr, "%s <command>\n", basename(cmd));
+ fprintf(stderr, "%s <statefile>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\n");
_exit(1);
}
if (!name)
usage(argv[0]);
+ if (!argv[1])
+ usage(argv[0]);
+
if (lxc_freeze(name)) {
fprintf(stderr, "failed to freeze '%s'\n", name);
return -1;
}
- if (lxc_checkpoint(name, STDOUT_FILENO, 0)) {
+ if (lxc_checkpoint(name, argv[1], 0)) {
fprintf(stderr, "failed to checkpoint %s\n", name);
goto out;
}
void usage(char *cmd)
{
- fprintf(stderr, "%s <command>\n", basename(cmd));
+ fprintf(stderr, "%s <statefile>\n", basename(cmd));
fprintf(stderr, "\t -n <name> : name of the container\n");
_exit(1);
}
if (!name)
usage(argv[0]);
- if (lxc_restart(name, STDIN_FILENO, 0)) {
+ if (!argv[1])
+ usage(argv[0]);
+
+ if (lxc_restart(name, argv[1], 0)) {
fprintf(stderr, "failed to restart %s\n", name);
return 1;
}
#include <sys/mount.h>
#include "error.h"
+#include "lxc_plugin.h"
#include <lxc/lxc.h>
LXC_TTY_HANDLER(SIGINT);
LXC_TTY_HANDLER(SIGQUIT);
-
-#if __i386__
-# define __NR_restart 334
-static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
-{
- return syscall(__NR_restart, pid, fd, flags);
-}
-#elif __x86_64__
-# define __NR_restart 296
-static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
-{
- return syscall(__NR_restart, pid, fd, flags);
-}
-#else
-static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
-{
- errno = ENOSYS;
- return -1;
-}
-# warning "Architecture not supported for restart syscall"
-#endif
-
-int lxc_restart(const char *name, int cfd, unsigned long flags)
+int lxc_restart(const char *name, const char *statefile,
+ unsigned long flags)
{
char *init = NULL, *val = NULL;
char ttyname[MAXPATHLEN];
if (!pid) {
+ char dummytty = '\0';
close(sv[1]);
/* Be sure we don't inherit this after the exec */
}
/* Setup the container, ip, names, utsname, ... */
- if (lxc_setup(name)) {
+ if (lxc_setup(name, &dummytty)) {
lxc_log_error("failed to setup the container");
if (write(sv[0], &sync, sizeof(sync)) < 0)
lxc_log_syserror("failed to write the socket");
return -1;
}
- sys_restart(getpid(), cfd, flags);
+ lxc_plugin_restart(getpid(), statefile, flags);
lxc_log_syserror("failed to restart");
/* If the exec fails, tell that to our father */