From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org,
dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org,
Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
Cc: Containers
<containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
Subject: [PATCH 2/4][user-cr] Rename struct args to struct restart_args
Date: Wed, 24 Feb 2010 00:36:23 -0800 [thread overview]
Message-ID: <20100224083623.GD18758@us.ibm.com> (raw)
In-Reply-To: <20100224083452.GB18758-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
From 8a6fad2170fbbeb7a5e44c32239f9703c0b7d2f9 Mon Sep 17 00:00:00 2001
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Tue, 23 Feb 2010 15:33:04 -0800
Subject: [PATCH 2/4][user-cr] Rename struct args to struct restart_args
Rename struct args to struct restart_args and move to a new header file,
usercr.h. usercr.h will become part of the external API for application
checkpoint restart code.
Also move the bulk of the restart code into a separate function,
app_restart() and have main() call the function.
TODO:
Cleanup 'struct restart_args' for a more consistent external API.
---
restart.c | 77 ++++++++++++++++++++++++------------------------------------
usercr.h | 24 +++++++++++++++++++
2 files changed, 55 insertions(+), 46 deletions(-)
create mode 100644 usercr.h
diff --git a/restart.c b/restart.c
index 7140786..b2281fb 100644
--- a/restart.c
+++ b/restart.c
@@ -40,6 +40,7 @@
#include "genstack.h"
#include "compat.h"
#include "restart.h"
+#include "usercr.h"
static char usage_str[] =
"usage: restart [opts]\n"
@@ -237,7 +238,7 @@ struct ckpt_ctx {
char container[BUFSIZE];
char tree[BUFSIZE];
char buf[BUFSIZE];
- struct args *args;
+ struct restart_args *args;
char *freezer;
};
@@ -310,28 +311,6 @@ struct pid_swap {
pid_t new;
};
-struct args {
- int self;
- int pids;
- int pidns;
- int no_pidns;
- int inspect;
- char *root;
- int wait;
- int mntns;
- int mnt_pty;
- int show_status;
- int copy_status;
- char *freezer;
- char *input;
- int infd;
- char *logfile;
- int logfd;
- long warn;
- long fail;
- int keep_lsm;
-};
-
static void usage(char *str)
{
fprintf(stderr, "%s", str);
@@ -382,7 +361,7 @@ static inline int ckpt_cond_fail(struct ckpt_ctx *ctx, long mask)
return (ctx->args->fail & mask);
}
-static void parse_args(struct args *args, int argc, char *argv[])
+static void parse_args(struct restart_args *args, int argc, char *argv[])
{
static struct option opts[] = {
{ "help", no_argument, NULL, 'h' },
@@ -712,71 +691,77 @@ static int freezer_register(struct ckpt_ctx *ctx, pid_t pid)
int main(int argc, char *argv[])
{
+ struct restart_args args;
+
+ parse_args(&args, argc, argv);
+
+ return app_restart(&args);
+}
+
+int app_restart(struct restart_args *args)
+{
struct ckpt_ctx ctx;
- struct args args;
int ret;
memset(&ctx, 0, sizeof(ctx));
-
- parse_args(&args, argc, argv);
- ctx.args = &args;
+ ctx.args = args;
/* input file ? */
- if (args.input) {
- args.infd = open(args.input, O_RDONLY, 0);
- if (args.infd < 0) {
+ if (args->input) {
+ args->infd = open(args->input, O_RDONLY, 0);
+ if (args->infd < 0) {
perror("open input file");
exit(1);
}
}
/* input file descriptor (default: stdin) */
- if (args.infd >= 0) {
- if (dup2(args.infd, STDIN_FILENO) < 0) {
+ if (args->infd >= 0) {
+ if (dup2(args->infd, STDIN_FILENO) < 0) {
perror("dup2 input file");
exit(1);
}
- if (args.infd != STDIN_FILENO)
- close(args.infd);
+ if (args->infd != STDIN_FILENO)
+ close(args->infd);
}
/* (optional) log file */
- if (args.logfile) {
- args.logfd = open(args.logfile,
+ if (args->logfile) {
+ args->logfd = open(args->logfile,
O_RDWR | O_CREAT | O_EXCL, 0644);
- if (args.logfd < 0) {
+ if (args->logfd < 0) {
perror("open log file");
exit(1);
}
}
/* output file descriptor (default: none) */
- if (args.logfd < 0)
- args.logfd = CHECKPOINT_FD_NONE;
+ if (args->logfd < 0)
+ args->logfd = CHECKPOINT_FD_NONE;
/* freezer preparation */
- if (args.freezer && freezer_prepare(&ctx) < 0)
+ if (args->freezer && freezer_prepare(&ctx) < 0)
exit(1);
/* private mounts namespace ? */
- if (args.mntns && unshare(CLONE_NEWNS | CLONE_FS) < 0) {
+ if (args->mntns && unshare(CLONE_NEWNS | CLONE_FS) < 0) {
perror("unshare");
exit(1);
}
/* chroot ? */
- if (args.root && chroot(args.root) < 0) {
+ if (args->root && chroot(args->root) < 0) {
perror("chroot");
exit(1);
}
/* remount /dev/pts ? */
- if (args.mnt_pty && ckpt_remount_devpts(&ctx) < 0)
+ if (args->mnt_pty && ckpt_remount_devpts(&ctx) < 0)
exit(1);
/* self-restart ends here: */
- if (args.self) {
- restart(getpid(), STDIN_FILENO, RESTART_TASKSELF, args.logfd);
+ if (args->self) {
+ restart(getpid(), STDIN_FILENO, RESTART_TASKSELF, args->logfd);
/* reach here if restart(2) failed ! */
perror("restart");
exit(1);
diff --git a/usercr.h b/usercr.h
new file mode 100644
index 0000000..71a36e6
--- /dev/null
+++ b/usercr.h
@@ -0,0 +1,24 @@
+
+struct restart_args {
+ int self;
+ int pids;
+ int pidns;
+ int no_pidns;
+ int inspect;
+ char *root;
+ int wait;
+ int mntns;
+ int mnt_pty;
+ int show_status;
+ int copy_status;
+ char *freezer;
+ char *input;
+ int infd;
+ char *logfile;
+ int logfd;
+ long warn;
+ long fail;
+ int keep_lsm;
+};
+
+extern int app_restart(struct restart_args *args);
--
1.6.6.1
next prev parent reply other threads:[~2010-02-24 8:36 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-24 8:34 [RFC][PATCH 0/4][user-cr]: First try at integrating LXC and USER-CR Sukadev Bhattiprolu
[not found] ` <20100224083452.GB18758-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-02-24 8:35 ` [PATCH 1/4][user-cr] Move common definitions to restart.h Sukadev Bhattiprolu
[not found] ` <20100224083534.GC18758-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-03 0:04 ` [PATCH] c/r: fix regression (in "fix scheduling in atomic while restoring ipc shm") Oren Laadan
[not found] ` <1267574649-14269-1-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2010-03-03 15:38 ` Serge E. Hallyn
2010-02-24 8:36 ` Sukadev Bhattiprolu [this message]
2010-02-24 8:36 ` [PATCH 3/4][user-cr] Move main() in restart.c to restart-main.c Sukadev Bhattiprolu
2010-02-24 8:37 ` [PATCH 4/4][user-cr] Rename libeclone.a to libcheckpoint.a Sukadev Bhattiprolu
[not found] ` <20100224083726.GF18758-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-02-24 15:19 ` Serge E. Hallyn
[not found] ` <20100224151919.GB6425-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-02-24 22:26 ` Sukadev Bhattiprolu
2010-02-26 21:53 ` Oren Laadan
[not found] ` <4B8842C8.9080707-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2010-02-27 1:44 ` Sukadev Bhattiprolu
2010-02-24 15:15 ` [RFC][PATCH 0/4][user-cr]: First try at integrating LXC and USER-CR Serge E. Hallyn
2010-02-24 18:25 ` Cedric Le Goater
2010-02-26 21:52 ` Oren Laadan
[not found] ` <4B88429B.4000701-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2010-02-27 0:10 ` Sukadev Bhattiprolu
[not found] ` <20100227001002.GA22965-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-02-27 2:14 ` Oren Laadan
2010-03-01 21:22 ` Oren Laadan
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=20100224083623.GD18758@us.ibm.com \
--to=sukadev-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org \
--cc=orenl-eQaUEPhvms7ENvBUuze7eA@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox