From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org,
dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org,
clg-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org
Cc: Containers
<containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
Subject: [PATCH 2/2][LXC] Have lxc_restart call app_restart()
Date: Wed, 24 Feb 2010 00:41:56 -0800 [thread overview]
Message-ID: <20100224084156.GH18758@us.ibm.com> (raw)
In-Reply-To: <20100224084108.GG18758-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
From 86023fbab91bc5c7a727e43e853615f27b70fbcf Mon Sep 17 00:00:00 2001
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Tue, 23 Feb 2010 22:38:14 -0800
Subject: [PATCH 2/2][LXC] Have lxc_restart call app_restart()
Have lxc_restart() call app_restart() exported by libcheckpoint.a from
the USER-CR git tree.
TODO: - Similarly implement lxc_checkpoint
- Use dynamic linking with liblxc.so
Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
src/lxc/Makefile2 | 16 +++++++++
src/lxc/restart.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 107 insertions(+), 0 deletions(-)
create mode 100644 src/lxc/Makefile2
diff --git a/src/lxc/Makefile2 b/src/lxc/Makefile2
new file mode 100644
index 0000000..9aba841
--- /dev/null
+++ b/src/lxc/Makefile2
@@ -0,0 +1,16 @@
+
+CFLAGS = -static -I . -I ..
+
+LDFLAGS = /lib/libcheckpoint.a -lutil
+
+LXC_OBJS = start.o conf.o confile.o arguments.o monitor.o log.o mainloop.o \
+ utils.o commands.o state.o cgroup.o error.o namespace.o \
+ parse.o network.o af_unix.o console.o nl.o stop.o
+
+RESTART_OBJS = $(LXC_OBJS) lxc_restart.o restart.o
+
+lxc_restart: $(RESTART_OBJS)
+ $(CC) -o lxc_restart $(RESTART_OBJS) $(LDFLAGS)
+
+clean:
+ rm -f $(RESTART_OBJS)
diff --git a/src/lxc/restart.c b/src/lxc/restart.c
index 467489e..b49939a 100644
--- a/src/lxc/restart.c
+++ b/src/lxc/restart.c
@@ -22,11 +22,102 @@
*/
#include <lxc/lxc.h>
#include <lxc/log.h>
+#include <lxc/start.h>
+#include <lxc/namespace.h>
+#include <errno.h>
+#include <signal.h>
+#include <sys/prctl.h>
+#include <usercr.h>
lxc_log_define(lxc_restart, lxc);
+struct lxc_restart_arg {
+ const char *name;
+ const char *statefile;
+ char *const argv;
+ struct lxc_handler *handler;
+};
+
+static int do_restart(struct lxc_restart_arg *lxcarg)
+{
+ int pid;
+ struct lxc_handler *handler = lxcarg->handler;
+ const char *name = lxcarg->name;
+ char *const argv = lxcarg->argv;
+ const char *statefile = lxcarg->statefile;
+ struct restart_args restart_args;
+
+ if (sigprocmask(SIG_SETMASK, &handler->oldmask, NULL)) {
+ SYSERROR("failed to set sigprocmask");
+ return -1;
+ }
+
+ if (prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0)) {
+ SYSERROR("failed to set pdeath signal");
+ return -1;
+ }
+
+ memset(&restart_args, 0, sizeof(restart_args));
+ restart_args.pids = 1;
+ restart_args.pidns = 1;
+ restart_args.no_pidns = 0;
+ restart_args.mnt_pty = 1;
+ restart_args.input = statefile;
+ restart_args.infd = -1;
+ restart_args.logfd = lxc_log_fd;
+ restart_args.wait = 0;
+
+ pid = app_restart(&restart_args);
+ return pid;
+}
+
int lxc_restart(const char *name, const char *statefile, struct lxc_conf *conf,
int flags)
{
+ int err;
+ int status;
+ struct lxc_handler *handler;
+ struct lxc_restart_arg lxcarg = {
+ .name = name,
+ .statefile = statefile,
+ .handler = NULL,
+ };
+
+ handler = lxc_init(name, conf);
+ if (!handler) {
+ ERROR("failed to initialize the container");
+ return -1;
+ }
+
+ lxcarg.handler = handler;
+ handler->pid = do_restart(&lxcarg);
+
+ lxc_rename_nsgroup(name, handler);
+
+ err = lxc_close_all_inherited_fd();
+ if (err) {
+ ERROR("unable to close inherited fds");
+ goto out_abort;
+ }
+
+ err = lxc_poll(name, handler);
+ if (err) {
+ ERROR("mainloop exited with an error");
+ goto out_abort;
+ }
+
+ while (waitpid(handler->pid, &status, 0) < 0 && errno == EINTR)
+ continue;
+
+ err = lxc_error_set_and_log(handler->pid, status);
+
+out_fini:
+ lxc_fini(name, handler);
+ return err;
+
+out_abort:
+ lxc_abort(name, handler);
+ goto out_fini;
+
return 0;
}
--
1.6.6.1
next prev parent reply other threads:[~2010-02-24 8:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-24 8:41 [PATCH 1/2][LXC] Rename --directory option to --statefile Sukadev Bhattiprolu
[not found] ` <20100224084108.GG18758-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-02-24 8:41 ` Sukadev Bhattiprolu [this message]
[not found] ` <20100224084156.GH18758-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-02-24 8:45 ` [PATCH 2/2][LXC] Have lxc_restart call app_restart() Cedric Le Goater
2010-02-24 8:49 ` [PATCH 1/2][LXC] Rename --directory option to --statefile Cedric Le Goater
[not found] ` <4B84E80A.7060208-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2010-02-24 8:54 ` Daniel Lezcano
[not found] ` <4B84E94E.3000406-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2010-02-24 18:11 ` Sukadev Bhattiprolu
[not found] ` <20100224181150.GA3276-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-02-24 18:11 ` Cedric Le Goater
[not found] ` <4B856BC8.5060000-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2010-02-24 18:30 ` Serge E. Hallyn
[not found] ` <20100224183024.GA22624-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-02-24 18:39 ` Cedric Le Goater
[not found] ` <4B85725C.3010002-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2010-02-24 18:45 ` Serge E. Hallyn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100224084156.GH18758@us.ibm.com \
--to=sukadev-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
--cc=clg-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org \
--cc=serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.