* [PATCH 0/12][user-cr]: Second set of cleanups
@ 2010-03-05 22:34 Sukadev Bhattiprolu
[not found] ` <20100305223439.GA15300-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 19+ messages in thread
From: Sukadev Bhattiprolu @ 2010-03-05 22:34 UTC (permalink / raw)
To: Oren Laadan; +Cc: sukadev-6JnAsaTVvkgX0ybBhKVfKdBPR1lH4CV8, Containers
Second set of cleanup patches. With these patches, LXC will be able
to compile/link directly using restart.o and app-checkpoint.h from
the user-cr directory. Something like:
USER_CR=/home/suka/user-cr make lxc_restart
After having more detailed discussions on the API, we could install
restart.o in /lib/libcheckpoint.a and app-checkpoint.h in /usr/include.
[PATCH 01/12][user-cr] restart: Mark globals as static
[PATCH 02/12][user-cr] restart: Add args->send_sigint
[PATCH 03/12][user-cr] Add app_restart_args->debug
[PATCH 04/12][user-cr] Add app_restart_args->verbose
[PATCH 05/12][user-cr] Add app_restart_args->ulogfd
[PATCH 06/12][user-cr] Add app_restart_args->uerrfd
[PATCH 07/12][user-cr] Define INIT_SIGNAL_ARRAY
[PATCH 08/12][user-cr] Create common.h
[PATCH 09/12][user-cr] Create app-checkpoint.h
[PATCH 10/12][user-cr] restart: Move main() to restart-main.c
[PATCH 11/12][user-cr] checkpoint: Move main() to checkpoint-main.c
[PATCH 12/12][user-cr] Have app_restart() return pid
Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
^ permalink raw reply [flat|nested] 19+ messages in thread
* [PATCH 01/12][user-cr] restart: Mark globals as static
[not found] ` <20100305223439.GA15300-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
@ 2010-03-05 22:36 ` Sukadev Bhattiprolu
2010-03-05 22:36 ` [PATCH 02/12][user-cr] restart: Add args->send_sigint Sukadev Bhattiprolu
` (11 subsequent siblings)
12 siblings, 0 replies; 19+ messages in thread
From: Sukadev Bhattiprolu @ 2010-03-05 22:36 UTC (permalink / raw)
To: Oren Laadan; +Cc: Containers
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Thu, 4 Mar 2010 17:41:04 -0800
Subject: [PATCH 01/12][user-cr] restart: Mark globals as static
app_restart() will in the future be exported to other programs.
To avoid potential variable-name collisions, make the globals
in restart.c static.
Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
restart.c | 18 +++++++++---------
1 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/restart.c b/restart.c
index 6994298..0c74bb6 100644
--- a/restart.c
+++ b/restart.c
@@ -301,15 +301,15 @@ struct ckpt_ctx {
* TODO: Do we need to direct user-space restart messages to two different
* fds (like stdout and stderr) or can we just use one ?
*/
-int global_ulogfd;
-int global_uerrfd;
-int global_debug;
-int global_verbose;
-pid_t global_child_pid;
-int global_child_status;
-int global_child_collected;
-int global_send_sigint = -1;
-int global_sent_sigint;
+static int global_ulogfd;
+static int global_uerrfd;
+static int global_debug;
+static int global_verbose;
+static pid_t global_child_pid;
+static int global_child_status;
+static int global_child_collected;
+static int global_send_sigint = -1;
+static int global_sent_sigint;
static int ckpt_remount_proc(struct ckpt_ctx *ctx);
static int ckpt_remount_devpts(struct ckpt_ctx *ctx);
--
1.6.0.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 02/12][user-cr] restart: Add args->send_sigint
[not found] ` <20100305223439.GA15300-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-05 22:36 ` [PATCH 01/12][user-cr] restart: Mark globals as static Sukadev Bhattiprolu
@ 2010-03-05 22:36 ` Sukadev Bhattiprolu
[not found] ` <20100305223658.GB15939-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-05 22:37 ` [PATCH 03/12][user-cr] Add app_restart_args->debug Sukadev Bhattiprolu
` (10 subsequent siblings)
12 siblings, 1 reply; 19+ messages in thread
From: Sukadev Bhattiprolu @ 2010-03-05 22:36 UTC (permalink / raw)
To: Oren Laadan; +Cc: Containers
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Thu, 4 Mar 2010 17:37:39 -0800
Subject: [PATCH 02/12][user-cr] restart: Add args->send_sigint
restart command supports a command line option, --send-sigint to let
user specify whether SIGINT signal should be processed/ignored during
restart. Make this a field in 'struct app_restart_args' so that other
callers of app_restart() in the future can also control the SIGINT
behavior.
Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
restart.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/restart.c b/restart.c
index 0c74bb6..314390c 100644
--- a/restart.c
+++ b/restart.c
@@ -376,6 +376,7 @@ struct app_restart_args {
int pids;
int pidns;
int inspect;
+ int send_sigint;
char *root;
int wait;
int mntns;
@@ -497,6 +498,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
args->klogfd = -1;
args->warn = CKPT_COND_WARN;
args->fail = CKPT_COND_FAIL;
+ args->send_sigint = -1;
no_pidns = 0;
klogfile = NULL;
@@ -554,7 +556,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
ckpt_err("restart: invalid signal\n");
exit(1);
}
- global_send_sigint = sig;
+ args->send_sigint = sig;
break;
case 3: /* --pids */
args->pids = 1;
@@ -815,6 +817,8 @@ int app_restart(struct app_restart_args *args)
memset(&ctx, 0, sizeof(ctx));
ctx.args = args;
+ global_send_sigint = args->send_sigint;
+
/* input file descriptor (default: stdin) */
if (args->infd >= 0) {
if (dup2(args->infd, STDIN_FILENO) < 0) {
--
1.6.0.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 03/12][user-cr] Add app_restart_args->debug
[not found] ` <20100305223439.GA15300-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-05 22:36 ` [PATCH 01/12][user-cr] restart: Mark globals as static Sukadev Bhattiprolu
2010-03-05 22:36 ` [PATCH 02/12][user-cr] restart: Add args->send_sigint Sukadev Bhattiprolu
@ 2010-03-05 22:37 ` Sukadev Bhattiprolu
[not found] ` <20100305223723.GC15939-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-05 22:37 ` [PATCH 04/12][user-cr] Add app_restart_args->verbose Sukadev Bhattiprolu
` (9 subsequent siblings)
12 siblings, 1 reply; 19+ messages in thread
From: Sukadev Bhattiprolu @ 2010-03-05 22:37 UTC (permalink / raw)
To: Oren Laadan; +Cc: Containers
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Thu, 4 Mar 2010 17:46:31 -0800
Subject: [PATCH 03/12][user-cr] Add app_restart_args->debug
Make 'debug' a field in struct app_restart_args so other callers of
app_restart() can also control the debug output of app_restart().
Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
restart.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/restart.c b/restart.c
index 314390c..87fff1e 100644
--- a/restart.c
+++ b/restart.c
@@ -387,6 +387,7 @@ struct app_restart_args {
int infd;
int klogfd;
long warn;
+ int debug;
long fail;
int keep_lsm;
};
@@ -583,7 +584,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
args->copy_status = 1;
break;
case 'd':
- global_debug = 1;
+ global_debug = args->debug = 1;
break;
case 'F':
args->freezer = optarg;
@@ -818,6 +819,7 @@ int app_restart(struct app_restart_args *args)
ctx.args = args;
global_send_sigint = args->send_sigint;
+ global_debug = args->debug;
/* input file descriptor (default: stdin) */
if (args->infd >= 0) {
--
1.6.0.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 04/12][user-cr] Add app_restart_args->verbose
[not found] ` <20100305223439.GA15300-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
` (2 preceding siblings ...)
2010-03-05 22:37 ` [PATCH 03/12][user-cr] Add app_restart_args->debug Sukadev Bhattiprolu
@ 2010-03-05 22:37 ` Sukadev Bhattiprolu
2010-03-05 22:38 ` [PATCH 05/12][user-cr] Add app_restart_args->ulogfd Sukadev Bhattiprolu
` (8 subsequent siblings)
12 siblings, 0 replies; 19+ messages in thread
From: Sukadev Bhattiprolu @ 2010-03-05 22:37 UTC (permalink / raw)
To: Oren Laadan; +Cc: Containers
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Thu, 4 Mar 2010 17:53:27 -0800
Subject: [PATCH 04/12][user-cr] Add app_restart_args->verbose
Make 'verbose' a field in struct app_restart_args so other callers of
app_restart() can also control the verbose output of app_restart().
Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
restart.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/restart.c b/restart.c
index 87fff1e..8513042 100644
--- a/restart.c
+++ b/restart.c
@@ -388,6 +388,7 @@ struct app_restart_args {
int klogfd;
long warn;
int debug;
+ int verbose;
long fail;
int keep_lsm;
};
@@ -515,7 +516,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
case 'h':
usage(usage_str);
case 'v':
- global_verbose = 1;
+ global_verbose = args->verbose = 1;
break;
case 5: /* --inspect */
args->inspect = 1;
@@ -820,6 +821,7 @@ int app_restart(struct app_restart_args *args)
global_send_sigint = args->send_sigint;
global_debug = args->debug;
+ global_verbose = args->verbose;
/* input file descriptor (default: stdin) */
if (args->infd >= 0) {
--
1.6.0.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 05/12][user-cr] Add app_restart_args->ulogfd
[not found] ` <20100305223439.GA15300-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
` (3 preceding siblings ...)
2010-03-05 22:37 ` [PATCH 04/12][user-cr] Add app_restart_args->verbose Sukadev Bhattiprolu
@ 2010-03-05 22:38 ` Sukadev Bhattiprolu
2010-03-05 22:38 ` [PATCH 06/12][user-cr] Add app_restart_args->uerrfd Sukadev Bhattiprolu
` (7 subsequent siblings)
12 siblings, 0 replies; 19+ messages in thread
From: Sukadev Bhattiprolu @ 2010-03-05 22:38 UTC (permalink / raw)
To: Oren Laadan; +Cc: Containers
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Thu, 4 Mar 2010 22:33:34 -0800
Subject: [PATCH 05/12][user-cr] Add app_restart_args->ulogfd
Add a 'ulogfd' field in struct app_restart_args so other callers of
app_restart() can also choose a file descriptor for the log messages
from app_restart().
Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
restart.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/restart.c b/restart.c
index 8513042..ac0acf3 100644
--- a/restart.c
+++ b/restart.c
@@ -386,6 +386,7 @@ struct app_restart_args {
char *freezer;
int infd;
int klogfd;
+ int ulogfd;
long warn;
int debug;
int verbose;
@@ -498,6 +499,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
args->wait = 1;
args->infd = -1;
args->klogfd = -1;
+ args->ulogfd = fileno(stdout);
args->warn = CKPT_COND_WARN;
args->fail = CKPT_COND_FAIL;
args->send_sigint = -1;
@@ -822,6 +824,7 @@ int app_restart(struct app_restart_args *args)
global_send_sigint = args->send_sigint;
global_debug = args->debug;
global_verbose = args->verbose;
+ global_ulogfd = args->ulogfd;
/* input file descriptor (default: stdin) */
if (args->infd >= 0) {
--
1.6.0.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 06/12][user-cr] Add app_restart_args->uerrfd
[not found] ` <20100305223439.GA15300-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
` (4 preceding siblings ...)
2010-03-05 22:38 ` [PATCH 05/12][user-cr] Add app_restart_args->ulogfd Sukadev Bhattiprolu
@ 2010-03-05 22:38 ` Sukadev Bhattiprolu
2010-03-05 22:38 ` [PATCH 07/12][user-cr] Define INIT_SIGNAL_ARRAY Sukadev Bhattiprolu
` (6 subsequent siblings)
12 siblings, 0 replies; 19+ messages in thread
From: Sukadev Bhattiprolu @ 2010-03-05 22:38 UTC (permalink / raw)
To: Oren Laadan; +Cc: Containers
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Thu, 4 Mar 2010 22:36:31 -0800
Subject: [PATCH 06/12][user-cr] Add app_restart_args->uerrfd
Add a 'uerrfd' field in struct app_restart_args so other callers of
app_restart() can also choose a file descriptor for the error messages
from app_restart().
Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
restart.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/restart.c b/restart.c
index ac0acf3..d4a4000 100644
--- a/restart.c
+++ b/restart.c
@@ -387,6 +387,7 @@ struct app_restart_args {
int infd;
int klogfd;
int ulogfd;
+ int uerrfd;
long warn;
int debug;
int verbose;
@@ -500,6 +501,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
args->infd = -1;
args->klogfd = -1;
args->ulogfd = fileno(stdout);
+ args->uerrfd = fileno(stderr);
args->warn = CKPT_COND_WARN;
args->fail = CKPT_COND_FAIL;
args->send_sigint = -1;
@@ -825,6 +827,7 @@ int app_restart(struct app_restart_args *args)
global_debug = args->debug;
global_verbose = args->verbose;
global_ulogfd = args->ulogfd;
+ global_uerrfd = args->uerrfd;
/* input file descriptor (default: stdin) */
if (args->infd >= 0) {
--
1.6.0.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 07/12][user-cr] Define INIT_SIGNAL_ARRAY
[not found] ` <20100305223439.GA15300-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
` (5 preceding siblings ...)
2010-03-05 22:38 ` [PATCH 06/12][user-cr] Add app_restart_args->uerrfd Sukadev Bhattiprolu
@ 2010-03-05 22:38 ` Sukadev Bhattiprolu
2010-03-05 22:39 ` [PATCH 08/12][user-cr] Create common.h Sukadev Bhattiprolu
` (5 subsequent siblings)
12 siblings, 0 replies; 19+ messages in thread
From: Sukadev Bhattiprolu @ 2010-03-05 22:38 UTC (permalink / raw)
To: Oren Laadan; +Cc: Containers
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Thu, 4 Mar 2010 21:15:25 -0800
Subject: [PATCH 07/12][user-cr] Define INIT_SIGNAL_ARRAY
Code to initialize the signal_array[] table will need to be shared by more
than one file. To enable this sharing with, define INIT_SIGNAL_ARRAY which
can later be used in many places.
Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
restart.c | 76 ++++++++++++++++++++++++++++++++-----------------------------
1 files changed, 40 insertions(+), 36 deletions(-)
diff --git a/restart.c b/restart.c
index d4a4000..b37bf81 100644
--- a/restart.c
+++ b/restart.c
@@ -157,46 +157,50 @@ static inline void ckpt_msg(int fd, char *format, ...)
ckpt_msg(global_ulogfd, __VA_ARGS__); \
} while(0)
-#define SIGNAL_ENTRY(signal) { SIG ## signal, #signal }
-
-struct {
+struct signal_array {
int signum;
char *sigstr;
-} signal_array[] = {
- { 0, "NONE" },
- SIGNAL_ENTRY(ALRM),
- SIGNAL_ENTRY(HUP),
- SIGNAL_ENTRY(INT),
- SIGNAL_ENTRY(KILL),
- SIGNAL_ENTRY(PIPE),
- SIGNAL_ENTRY(POLL),
- SIGNAL_ENTRY(PROF),
- SIGNAL_ENTRY(TERM),
- SIGNAL_ENTRY(USR1),
- SIGNAL_ENTRY(USR2),
- SIGNAL_ENTRY(VTALRM),
- SIGNAL_ENTRY(STKFLT),
- SIGNAL_ENTRY(PWR),
- SIGNAL_ENTRY(WINCH),
- SIGNAL_ENTRY(CHLD),
- SIGNAL_ENTRY(URG),
- SIGNAL_ENTRY(TTIN),
- SIGNAL_ENTRY(TTOU),
- SIGNAL_ENTRY(STOP),
- SIGNAL_ENTRY(CONT),
- SIGNAL_ENTRY(ABRT),
- SIGNAL_ENTRY(FPE),
- SIGNAL_ENTRY(ILL),
- SIGNAL_ENTRY(QUIT),
- SIGNAL_ENTRY(SEGV),
- SIGNAL_ENTRY(TRAP),
- SIGNAL_ENTRY(SYS),
- SIGNAL_ENTRY(BUS),
- SIGNAL_ENTRY(XCPU),
- SIGNAL_ENTRY(XFSZ),
- { -1, "LAST" },
};
+#define SIGNAL_ENTRY(signal) { SIG ## signal, #signal }
+
+#define INIT_SIGNAL_ARRAY { \
+ { 0, "NONE" }, \
+ SIGNAL_ENTRY(ALRM), \
+ SIGNAL_ENTRY(HUP), \
+ SIGNAL_ENTRY(INT), \
+ SIGNAL_ENTRY(KILL), \
+ SIGNAL_ENTRY(PIPE), \
+ SIGNAL_ENTRY(POLL), \
+ SIGNAL_ENTRY(PROF), \
+ SIGNAL_ENTRY(TERM), \
+ SIGNAL_ENTRY(USR1), \
+ SIGNAL_ENTRY(USR2), \
+ SIGNAL_ENTRY(VTALRM), \
+ SIGNAL_ENTRY(STKFLT), \
+ SIGNAL_ENTRY(PWR), \
+ SIGNAL_ENTRY(WINCH), \
+ SIGNAL_ENTRY(CHLD), \
+ SIGNAL_ENTRY(URG), \
+ SIGNAL_ENTRY(TTIN), \
+ SIGNAL_ENTRY(TTOU), \
+ SIGNAL_ENTRY(STOP), \
+ SIGNAL_ENTRY(CONT), \
+ SIGNAL_ENTRY(ABRT), \
+ SIGNAL_ENTRY(FPE), \
+ SIGNAL_ENTRY(ILL), \
+ SIGNAL_ENTRY(QUIT), \
+ SIGNAL_ENTRY(SEGV), \
+ SIGNAL_ENTRY(TRAP), \
+ SIGNAL_ENTRY(SYS), \
+ SIGNAL_ENTRY(BUS), \
+ SIGNAL_ENTRY(XCPU), \
+ SIGNAL_ENTRY(XFSZ), \
+ { -1, "LAST" }, \
+}
+
+static struct signal_array signal_array[] = INIT_SIGNAL_ARRAY;
+
static char *sig2str(int sig)
{
int i = 0;
--
1.6.0.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 08/12][user-cr] Create common.h
[not found] ` <20100305223439.GA15300-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
` (6 preceding siblings ...)
2010-03-05 22:38 ` [PATCH 07/12][user-cr] Define INIT_SIGNAL_ARRAY Sukadev Bhattiprolu
@ 2010-03-05 22:39 ` Sukadev Bhattiprolu
[not found] ` <20100305223907.GH15939-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-05 22:39 ` [PATCH 09/12][user-cr] Create app-checkpoint.h Sukadev Bhattiprolu
` (4 subsequent siblings)
12 siblings, 1 reply; 19+ messages in thread
From: Sukadev Bhattiprolu @ 2010-03-05 22:39 UTC (permalink / raw)
To: Oren Laadan; +Cc: Containers
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Thu, 4 Mar 2010 21:30:50 -0800
Subject: [PATCH 08/12][user-cr] Create common.h
Code in common.h can be shared by checkpoint.c and restart.c for now.
Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
Makefile | 4 ++
checkpoint.c | 31 +---------------
common.h | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
restart.c | 110 +--------------------------------------------------------
4 files changed, 119 insertions(+), 138 deletions(-)
create mode 100644 common.h
diff --git a/Makefile b/Makefile
index b312358..acebdd5 100644
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,8 @@ CKPT_HEADERS = include/linux/checkpoint.h \
include/linux/checkpoint_hdr.h \
include/asm/checkpoint_hdr.h
+CR_OBJS = checkpoint.o restart.o
+
# detect architecture (for eclone)
SUBARCH = $(patsubst i%86,x86_32,$(shell uname -m))
@@ -41,6 +43,8 @@ $(LIB_ECLONE):
# restart needs to be thread-safe
restart: CFLAGS += -D__REENTRANT -pthread
+$(CR_OBJS): common.h
+
# eclone() is architecture specific
ifneq ($(SUBARCH),)
$(ECLONE_PROGS): $(LIB_ECLONE)
diff --git a/checkpoint.c b/checkpoint.c
index ace17e2..6e91149 100644
--- a/checkpoint.c
+++ b/checkpoint.c
@@ -21,6 +21,8 @@
#include <linux/checkpoint.h>
+#include "common.h"
+
static char usage_str[] =
"usage: ckpt [opts] PID\n"
" 'checkpoint' takes a checkpoint of the task indicated by PID, and all\n"
@@ -55,35 +57,6 @@ inline static int checkpoint(pid_t pid, int fd, unsigned long flags, int logfd)
return syscall(__NR_checkpoint, pid, fd, flags, logfd);
}
-#define BUFSIZE (4 * 4096)
-static inline void ckpt_msg(int fd, char *format, ...)
-{
- va_list ap;
- char *bufp;
- if (fd < 0)
- return;
-
- va_start(ap, format);
-
- bufp = malloc(BUFSIZE);
- if(bufp) {
- vsnprintf(bufp, BUFSIZE, format, ap);
- write(fd, bufp, strlen(bufp));
- }
- free(bufp);
-
- va_end(ap);
-}
-
-#define ckpt_err(...) \
- ckpt_msg(global_uerrfd, __VA_ARGS__)
-
-#define ckpt_perror(s) \
- do { \
- ckpt_msg(global_uerrfd, s); \
- ckpt_msg(global_uerrfd, ": %s\n", strerror(errno)); \
- } while (0)
-
static void usage(char *str)
{
ckpt_err("%s", str);
diff --git a/common.h b/common.h
new file mode 100644
index 0000000..99b224d
--- /dev/null
+++ b/common.h
@@ -0,0 +1,112 @@
+#include <stdio.h>
+#include <signal.h>
+
+#define BUFSIZE (4 * 4096)
+
+static inline void ckpt_msg(int fd, char *format, ...)
+{
+ va_list ap;
+ char *bufp;
+ if (fd < 0)
+ return;
+
+ va_start(ap, format);
+
+ bufp = malloc(BUFSIZE);
+ if(bufp) {
+ vsnprintf(bufp, BUFSIZE, format, ap);
+ write(fd, bufp, strlen(bufp));
+ }
+ free(bufp);
+
+ va_end(ap);
+}
+
+#define ckpt_perror(s) \
+ do { \
+ ckpt_msg(global_uerrfd, s); \
+ ckpt_msg(global_uerrfd, ": %s\n", strerror(errno)); \
+ } while (0)
+
+#ifdef CHECKPOINT_DEBUG
+#define ckpt_dbg(_format, _args...) \
+ do { \
+ if (global_debug) \
+ ckpt_msg(global_uerrfd, "<%d>" _format, \
+ _gettid(), ##_args); \
+ } while (0)
+#define ckpt_dbg_cont(_format, _args...) \
+ do { \
+ if (global_debug) \
+ ckpt_msg(global_uerrfd, _format, ##_args); \
+ } while (0)
+#else
+#define ckpt_dbg(_format, _args...) \
+ do { } while (0)
+#define ckpt_dbg_cont(_format, _args...) \
+ do { } while (0)
+#endif
+
+#define ckpt_err(...) \
+ ckpt_msg(global_uerrfd, __VA_ARGS__)
+
+#define ckpt_verbose(...) \
+ do { \
+ if (global_verbose) \
+ ckpt_msg(global_ulogfd, __VA_ARGS__); \
+ } while(0)
+
+struct signal_array {
+ int signum;
+ char *sigstr;
+};
+
+#define SIGNAL_ENTRY(signal) { SIG ## signal, #signal }
+
+#define INIT_SIGNAL_ARRAY { \
+ { 0, "NONE" }, \
+ SIGNAL_ENTRY(ALRM), \
+ SIGNAL_ENTRY(HUP), \
+ SIGNAL_ENTRY(INT), \
+ SIGNAL_ENTRY(KILL), \
+ SIGNAL_ENTRY(PIPE), \
+ SIGNAL_ENTRY(POLL), \
+ SIGNAL_ENTRY(PROF), \
+ SIGNAL_ENTRY(TERM), \
+ SIGNAL_ENTRY(USR1), \
+ SIGNAL_ENTRY(USR2), \
+ SIGNAL_ENTRY(VTALRM), \
+ SIGNAL_ENTRY(STKFLT), \
+ SIGNAL_ENTRY(PWR), \
+ SIGNAL_ENTRY(WINCH), \
+ SIGNAL_ENTRY(CHLD), \
+ SIGNAL_ENTRY(URG), \
+ SIGNAL_ENTRY(TTIN), \
+ SIGNAL_ENTRY(TTOU), \
+ SIGNAL_ENTRY(STOP), \
+ SIGNAL_ENTRY(CONT), \
+ SIGNAL_ENTRY(ABRT), \
+ SIGNAL_ENTRY(FPE), \
+ SIGNAL_ENTRY(ILL), \
+ SIGNAL_ENTRY(QUIT), \
+ SIGNAL_ENTRY(SEGV), \
+ SIGNAL_ENTRY(TRAP), \
+ SIGNAL_ENTRY(SYS), \
+ SIGNAL_ENTRY(BUS), \
+ SIGNAL_ENTRY(XCPU), \
+ SIGNAL_ENTRY(XFSZ), \
+ { -1, "LAST" }, \
+}
+
+#define CKPT_COND_PIDZERO 0x1
+#define CKPT_COND_MNTPROC 0x2
+#define CKPT_COND_MNTPTY 0x4
+
+#define CKPT_COND_NONE 0
+#define CKPT_COND_ANY ULONG_MAX
+
+/* default for skip/warn/fail */
+#define CKPT_COND_WARN (CKPT_COND_MNTPROC | \
+ CKPT_COND_MNTPTY)
+#define CKPT_COND_FAIL (CKPT_COND_NONE)
+
diff --git a/restart.c b/restart.c
index b37bf81..f65eafb 100644
--- a/restart.c
+++ b/restart.c
@@ -40,6 +40,7 @@
#include "eclone.h"
#include "genstack.h"
#include "compat.h"
+#include "common.h"
static char usage_str[] =
"usage: restart [opts]\n"
@@ -102,103 +103,6 @@ static char usage_str[] =
* of the checkpoint image stream.
*/
-#define BUFSIZE (4 * 4096)
-
-static inline void ckpt_msg(int fd, char *format, ...)
-{
- va_list ap;
- char *bufp;
- if (fd < 0)
- return;
-
- va_start(ap, format);
-
- bufp = malloc(BUFSIZE);
- if(bufp) {
- vsnprintf(bufp, BUFSIZE, format, ap);
- write(fd, bufp, strlen(bufp));
- }
- free(bufp);
-
- va_end(ap);
-}
-
-#define ckpt_perror(s) \
- do { \
- ckpt_msg(global_uerrfd, s); \
- ckpt_msg(global_uerrfd, ": %s\n", strerror(errno)); \
- } while (0)
-
-#ifdef CHECKPOINT_DEBUG
-#define ckpt_dbg(_format, _args...) \
- do { \
- if (global_debug) \
- ckpt_msg(global_uerrfd, "<%d>" _format, \
- _gettid(), ##_args); \
- } while (0)
-#define ckpt_dbg_cont(_format, _args...) \
- do { \
- if (global_debug) \
- ckpt_msg(global_uerrfd, _format, ##_args); \
- } while (0)
-#else
-#define ckpt_dbg(_format, _args...) \
- do { } while (0)
-#define ckpt_dbg_cont(_format, _args...) \
- do { } while (0)
-#endif
-
-#define ckpt_err(...) \
- ckpt_msg(global_uerrfd, __VA_ARGS__)
-
-#define ckpt_verbose(...) \
- do { \
- if (global_verbose) \
- ckpt_msg(global_ulogfd, __VA_ARGS__); \
- } while(0)
-
-struct signal_array {
- int signum;
- char *sigstr;
-};
-
-#define SIGNAL_ENTRY(signal) { SIG ## signal, #signal }
-
-#define INIT_SIGNAL_ARRAY { \
- { 0, "NONE" }, \
- SIGNAL_ENTRY(ALRM), \
- SIGNAL_ENTRY(HUP), \
- SIGNAL_ENTRY(INT), \
- SIGNAL_ENTRY(KILL), \
- SIGNAL_ENTRY(PIPE), \
- SIGNAL_ENTRY(POLL), \
- SIGNAL_ENTRY(PROF), \
- SIGNAL_ENTRY(TERM), \
- SIGNAL_ENTRY(USR1), \
- SIGNAL_ENTRY(USR2), \
- SIGNAL_ENTRY(VTALRM), \
- SIGNAL_ENTRY(STKFLT), \
- SIGNAL_ENTRY(PWR), \
- SIGNAL_ENTRY(WINCH), \
- SIGNAL_ENTRY(CHLD), \
- SIGNAL_ENTRY(URG), \
- SIGNAL_ENTRY(TTIN), \
- SIGNAL_ENTRY(TTOU), \
- SIGNAL_ENTRY(STOP), \
- SIGNAL_ENTRY(CONT), \
- SIGNAL_ENTRY(ABRT), \
- SIGNAL_ENTRY(FPE), \
- SIGNAL_ENTRY(ILL), \
- SIGNAL_ENTRY(QUIT), \
- SIGNAL_ENTRY(SEGV), \
- SIGNAL_ENTRY(TRAP), \
- SIGNAL_ENTRY(SYS), \
- SIGNAL_ENTRY(BUS), \
- SIGNAL_ENTRY(XCPU), \
- SIGNAL_ENTRY(XFSZ), \
- { -1, "LAST" }, \
-}
-
static struct signal_array signal_array[] = INIT_SIGNAL_ARRAY;
static char *sig2str(int sig)
@@ -399,18 +303,6 @@ struct app_restart_args {
int keep_lsm;
};
-#define CKPT_COND_PIDZERO 0x1
-#define CKPT_COND_MNTPROC 0x2
-#define CKPT_COND_MNTPTY 0x4
-
-#define CKPT_COND_NONE 0
-#define CKPT_COND_ANY ULONG_MAX
-
-/* default for skip/warn/fail */
-#define CKPT_COND_WARN (CKPT_COND_MNTPROC | \
- CKPT_COND_MNTPTY)
-#define CKPT_COND_FAIL (CKPT_COND_NONE)
-
static void usage(char *str)
{
ckpt_err("%s", str);
--
1.6.0.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 09/12][user-cr] Create app-checkpoint.h
[not found] ` <20100305223439.GA15300-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
` (7 preceding siblings ...)
2010-03-05 22:39 ` [PATCH 08/12][user-cr] Create common.h Sukadev Bhattiprolu
@ 2010-03-05 22:39 ` Sukadev Bhattiprolu
2010-03-05 22:39 ` [PATCH 10/12][user-cr] restart: Move main() to restart-main.c Sukadev Bhattiprolu
` (3 subsequent siblings)
12 siblings, 0 replies; 19+ messages in thread
From: Sukadev Bhattiprolu @ 2010-03-05 22:39 UTC (permalink / raw)
To: Oren Laadan; +Cc: Containers
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Thu, 4 Mar 2010 21:51:27 -0800
Subject: [PATCH 09/12][user-cr] Create app-checkpoint.h
Create a new header file, app-checkpoint.h that can be used to export
the app_checkpoint() and app_restart() functionality to other users
(such as LXC).
Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
Makefile | 2 +-
app-checkpoint.h | 37 +++++++++++++++++++++++++++++++++++++
checkpoint.c | 9 +--------
restart.c | 25 +------------------------
4 files changed, 40 insertions(+), 33 deletions(-)
create mode 100644 app-checkpoint.h
diff --git a/Makefile b/Makefile
index acebdd5..b037f93 100644
--- a/Makefile
+++ b/Makefile
@@ -43,7 +43,7 @@ $(LIB_ECLONE):
# restart needs to be thread-safe
restart: CFLAGS += -D__REENTRANT -pthread
-$(CR_OBJS): common.h
+$(CR_OBJS): common.h app-checkpoint.h
# eclone() is architecture specific
ifneq ($(SUBARCH),)
diff --git a/app-checkpoint.h b/app-checkpoint.h
new file mode 100644
index 0000000..75204b5
--- /dev/null
+++ b/app-checkpoint.h
@@ -0,0 +1,37 @@
+
+struct app_checkpoint_args {
+ int outfd;
+ int logfd;
+ int uerrfd;
+ int container;
+ int verbose;
+};
+
+struct app_restart_args {
+ int self;
+ int pids;
+ int pidns;
+ int inspect;
+ int send_sigint;
+ char *root;
+ int wait;
+ int mntns;
+ int mnt_pty;
+ int show_status;
+ int copy_status;
+ char *freezer;
+ int infd;
+ int klogfd;
+ int ulogfd;
+ int uerrfd;
+ long warn;
+ int debug;
+ int verbose;
+ long fail;
+ int keep_lsm;
+};
+
+extern int app_checkpoint(int pid, unsigned long flags,
+ struct app_checkpoint_args *args);
+
+extern int app_restart(struct app_restart_args *args);
diff --git a/checkpoint.c b/checkpoint.c
index 6e91149..291cb36 100644
--- a/checkpoint.c
+++ b/checkpoint.c
@@ -21,6 +21,7 @@
#include <linux/checkpoint.h>
+#include "app-checkpoint.h"
#include "common.h"
static char usage_str[] =
@@ -44,14 +45,6 @@ static char usage_str[] =
static int global_uerrfd = -1;
-struct app_checkpoint_args {
- int outfd;
- int logfd;
- int uerrfd;
- int container;
- int verbose;
-};
-
inline static int checkpoint(pid_t pid, int fd, unsigned long flags, int logfd)
{
return syscall(__NR_checkpoint, pid, fd, flags, logfd);
diff --git a/restart.c b/restart.c
index f65eafb..a9b287d 100644
--- a/restart.c
+++ b/restart.c
@@ -40,6 +40,7 @@
#include "eclone.h"
#include "genstack.h"
#include "compat.h"
+#include "app-checkpoint.h"
#include "common.h"
static char usage_str[] =
@@ -279,30 +280,6 @@ struct pid_swap {
pid_t new;
};
-struct app_restart_args {
- int self;
- int pids;
- int pidns;
- int inspect;
- int send_sigint;
- char *root;
- int wait;
- int mntns;
- int mnt_pty;
- int show_status;
- int copy_status;
- char *freezer;
- int infd;
- int klogfd;
- int ulogfd;
- int uerrfd;
- long warn;
- int debug;
- int verbose;
- long fail;
- int keep_lsm;
-};
-
static void usage(char *str)
{
ckpt_err("%s", str);
--
1.6.0.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 10/12][user-cr] restart: Move main() to restart-main.c
[not found] ` <20100305223439.GA15300-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
` (8 preceding siblings ...)
2010-03-05 22:39 ` [PATCH 09/12][user-cr] Create app-checkpoint.h Sukadev Bhattiprolu
@ 2010-03-05 22:39 ` Sukadev Bhattiprolu
2010-03-05 22:40 ` [PATCH 11/12][user-cr] checkpoint: Move main() to checkpoint-main.c Sukadev Bhattiprolu
` (2 subsequent siblings)
12 siblings, 0 replies; 19+ messages in thread
From: Sukadev Bhattiprolu @ 2010-03-05 22:39 UTC (permalink / raw)
To: Oren Laadan; +Cc: Containers
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Thu, 4 Mar 2010 21:46:14 -0800
Subject: [PATCH 10/12][user-cr] restart: Move main() to restart-main.c
Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
Makefile | 4 +-
restart-main.c | 351 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
restart.c | 332 -----------------------------------------------------
3 files changed, 354 insertions(+), 333 deletions(-)
create mode 100644 restart-main.c
diff --git a/Makefile b/Makefile
index b037f93..8a91d10 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ CKPT_HEADERS = include/linux/checkpoint.h \
include/linux/checkpoint_hdr.h \
include/asm/checkpoint_hdr.h
-CR_OBJS = checkpoint.o restart.o
+CR_OBJS = checkpoint.o restart.o restart-main.o
# detect architecture (for eclone)
SUBARCH = $(patsubst i%86,x86_32,$(shell uname -m))
@@ -45,6 +45,8 @@ restart: CFLAGS += -D__REENTRANT -pthread
$(CR_OBJS): common.h app-checkpoint.h
+restart: restart.o restart-main.o
+
# eclone() is architecture specific
ifneq ($(SUBARCH),)
$(ECLONE_PROGS): $(LIB_ECLONE)
diff --git a/restart-main.c b/restart-main.c
new file mode 100644
index 0000000..96bca42
--- /dev/null
+++ b/restart-main.c
@@ -0,0 +1,351 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <limits.h>
+#include <getopt.h>
+
+#include "app-checkpoint.h"
+#include "common.h"
+
+static int global_ulogfd;
+static int global_uerrfd;
+static int global_debug;
+static int global_verbose;
+static struct signal_array signal_array[] = INIT_SIGNAL_ARRAY;
+
+static char usage_str[] =
+"usage: restart [opts]\n"
+" restart restores from a checkpoint image by first creating in userspace\n"
+" the original tasks tree, and then calling sys_restart by each task.\n"
+"Options:\n"
+" -h,--help print this help message\n"
+" -p,--pidns create a new pid namspace (default with --pids)\n"
+" -P,--no-pidns do not create a new pid namespace (default)\n"
+" --pids restore original pids (default with --pidns)\n"
+" --self restart a single task, usually from self-checkpoint\n"
+" -r,--root=ROOT restart under the directory ROOT instead of current\n"
+" --signal=SIG send SIG to root task on SIGINT (default: SIGKILL\n"
+" to container root, SIGINT otherwise)\n"
+" --mntns restart under a private mounts namespace\n"
+" --mount-pty start in a new devpts namespace to supprt ptys\n"
+" -w,--wait wait for root task to termiate (default)\n"
+" --show-status show exit status of root task (implies -w)\n"
+" --copy-status imitate exit status of root task (implies -w)\n"
+" -W,--no-wait do not wait for root task to terminate\n"
+" -k,--keeplsm try to recreate original LSM labels on all objects\n"
+" -F,--freezer=CGROUP freeze tasks in freezer group CGROUP on success\n"
+" -i,--input=FILE read data from FILE instead of standard input\n"
+" --input-fd=FD read data from file descriptor FD (instead of stdin)\n"
+" -l,--logfile=FILE write error and debug data to FILE (default=none)\n"
+" --logfile-fd=FD write error and debug data to file desctiptor FD\n"
+" --inspect inspect image on-the-fly for error records\n"
+" -v,--verbose verbose output\n"
+" -d,--debug debugging output\n"
+" --skip-COND skip condition COND, and proceed anyway\n"
+" --warn-COND warn on condition COND, but proceed anyway\n"
+" --fail-COND warn on condition COND, and abort operation\n"
+" COND=any: any condition\n"
+" COND=pidzero: task with sid/pgid zero in a --no-pidns restart\n"
+" COND=mntproc: /proc isn't already mounted at restart (def: warn)\n"
+"";
+
+static void usage(char *str)
+{
+ ckpt_err("%s", str);
+ exit(1);
+}
+
+/* negative retval means error */
+static int str2num(char *str)
+{
+ char *nptr;
+ int num;
+
+ num = strtol(str, &nptr, 10);
+ if (nptr - str != strlen(str))
+ num = -1;
+ return num;
+}
+
+static long cond_to_mask(const char *cond)
+{
+ static struct {
+ char *cond;
+ long mask;
+ } conditions[] = {
+ {"pidzero", CKPT_COND_PIDZERO},
+ {"mntproc", CKPT_COND_MNTPROC},
+ {"any", CKPT_COND_ANY},
+ {NULL, 0}
+ };
+
+ int i;
+
+ for (i = 0; conditions[i].cond; i++)
+ if (!strcmp(cond, conditions[i].cond))
+ return conditions[i].mask;
+
+ ckpt_err("restart: invalid warn/fail condition '%s'\n", cond);
+ exit(1);
+}
+
+static int str2sig(char *str)
+{
+ int sig = 0;
+
+ do {
+ if (!strcmp(signal_array[sig].sigstr, str))
+ return signal_array[sig].signum;
+ } while (signal_array[++sig].signum >= 0);
+
+ return -1;
+}
+
+static void parse_args(struct app_restart_args *args, int argc, char *argv[])
+{
+ static struct option opts[] = {
+ { "help", no_argument, NULL, 'h' },
+ { "pidns", no_argument, NULL, 'p' },
+ { "no-pidns", no_argument, NULL, 'P' },
+ { "pids", no_argument, NULL, 3 },
+ { "self", no_argument, NULL, 6},
+ { "signal", required_argument, NULL, 4 },
+ { "inspect", no_argument, NULL, 5 },
+ { "keeplsm", no_argument, NULL, 'k' },
+ { "input", required_argument, NULL, 'i' },
+ { "input-fd", required_argument, NULL, 7 },
+ { "logfile", required_argument, NULL, 'l' },
+ { "logfile-fd", required_argument, NULL, 8 },
+ { "root", required_argument, NULL, 'r' },
+ { "mntns", no_argument, NULL, 11 },
+ { "wait", no_argument, NULL, 'w' },
+ { "show-status", no_argument, NULL, 1 },
+ { "copy-status", no_argument, NULL, 2 },
+ { "no-wait", no_argument, NULL, 'W' },
+ { "freezer", required_argument, NULL, 'F' },
+ { "verbose", no_argument, NULL, 'v' },
+ { "debug", no_argument, NULL, 'd' },
+ { "warn-pidzero", no_argument, NULL, 9 },
+ { "fail-pidzero", no_argument, NULL, 10 },
+ { "mount-pty", no_argument, NULL, 12 },
+ { NULL, 0, NULL, 0 }
+ };
+ static char optc[] = "hdvkpPwWF:r:i:l:";
+
+ int optind;
+ int sig;
+ int no_pidns;
+
+ char *klogfile;
+ char *input;
+
+ /* defaults */
+ memset(args, 0, sizeof(*args));
+ args->wait = 1;
+ args->infd = -1;
+ args->klogfd = -1;
+ args->ulogfd = fileno(stdout);
+ args->uerrfd = fileno(stderr);
+ args->warn = CKPT_COND_WARN;
+ args->fail = CKPT_COND_FAIL;
+ args->send_sigint = -1;
+ no_pidns = 0;
+
+ klogfile = NULL;
+ input = NULL;
+
+ while (1) {
+ int c = getopt_long(argc, argv, optc, opts, &optind);
+ if (c == -1)
+ break;
+ switch (c) {
+ case '?':
+ exit(1);
+ case 'h':
+ usage(usage_str);
+ case 'v':
+ global_verbose = args->verbose = 1;
+ break;
+ case 5: /* --inspect */
+ args->inspect = 1;
+ break;
+ case 'i':
+ input = optarg;
+ break;
+ case 7:
+ args->infd = str2num(optarg);
+ if (args->infd < 0) {
+ ckpt_err("restart: invalid file descriptor\n");
+ exit(1);
+ }
+ break;
+ case 'l':
+ klogfile = optarg;
+ break;
+ case 8:
+ args->klogfd = str2num(optarg);
+ if (args->klogfd < 0) {
+ ckpt_err("restart: invalid file descriptor\n");
+ exit(1);
+ }
+ break;
+ case 'p':
+ args->pidns = 1;
+ break;
+ case 'P':
+ no_pidns = 1;
+ break;
+ case 6: /* --self */
+ args->self = 1;
+ break;
+ case 4: /* --signal */
+ sig = str2sig(optarg);
+ if (sig < 0)
+ sig = str2num(optarg);
+ if (sig < 0 || sig >= NSIG) {
+ ckpt_err("restart: invalid signal\n");
+ exit(1);
+ }
+ args->send_sigint = sig;
+ break;
+ case 3: /* --pids */
+ args->pids = 1;
+ args->pidns = 1; /* implied */
+ break;
+ case 'r':
+ args->root = optarg;
+ break;
+ case 'w':
+ args->wait = 1;
+ break;
+ case 'W':
+ args->wait = 0;
+ break;
+ case 'k':
+ args->keep_lsm = 1;
+ break;
+ case 1: /* --show-status */
+ args->wait = 1;
+ args->show_status = 1;
+ break;
+ case 2: /* --copy-status */
+ args->wait = 1;
+ args->copy_status = 1;
+ break;
+ case 'd':
+ global_debug = args->debug = 1;
+ break;
+ case 'F':
+ args->freezer = optarg;
+ break;
+ case 9:
+ args->warn |= cond_to_mask(&opts[optind].name[5]);
+ break;
+ case 10:
+ args->fail |= cond_to_mask(&opts[optind].name[5]);
+ break;
+ case 11:
+ args->mntns = 1;
+ break;
+ case 12:
+ args->mnt_pty = 1;
+ break;
+ default:
+ usage(usage_str);
+ }
+ }
+
+ if (no_pidns)
+ args->pidns = 0;
+
+#ifndef CLONE_NEWPID
+ if (args->pidns) {
+ ckpt_err("This version of restart was compiled without "
+ "support for --pidns.\n");
+ exit(1);
+ }
+#endif
+
+#ifndef CHECKPOINT_DEBUG
+ if (global_debug) {
+ ckpt_err("This version of restart was compiled without "
+ "support for --debug.\n");
+ exit(1);
+ }
+#endif
+
+ if (args->pidns)
+ args->pids = 1;
+
+#if 0 /* Defered until __NR_eclone makes it to standard headers */
+#ifndef __NR_eclone
+ if (args->pids) {
+ ckpt_err("This version of restart was compiled without "
+ "support for --pids.\n");
+ exit(1);
+ }
+#endif
+#endif
+
+ if (args->self &&
+ (args->pids || args->pidns || no_pidns ||
+ args->show_status || args->copy_status || args->freezer)) {
+ ckpt_err("Invalid mix of --self with multiprocess options\n");
+ exit(1);
+ }
+
+ if (input && args->infd >= 0) {
+ ckpt_err("Invalid use of both -i/--input and --input-fd\n");
+ exit(1);
+ }
+
+ /* input file ? */
+ if (input) {
+ args->infd = open(input, O_RDONLY, 0);
+ if (args->infd < 0) {
+ ckpt_perror("open input file");
+ exit(1);
+ }
+ }
+
+ if (klogfile && args->klogfd >= 0) {
+ ckpt_err("Invalid use of both -l/--logfile and --logfile-fd\n");
+ exit(1);
+ }
+
+ /* (optional) log file */
+ if (klogfile) {
+ args->klogfd = open(klogfile, O_RDWR | O_CREAT | O_EXCL, 0644);
+ if (args->klogfd < 0) {
+ ckpt_perror("open log file");
+ exit(1);
+ }
+ }
+
+
+ if (args->mnt_pty)
+ args->mntns = 1;
+}
+
+int main(int argc, char *argv[])
+{
+ struct app_restart_args args;
+
+ /*
+ * Initialize the log/error fds early so even parse_args() errors
+ * are redirected here. Even if we later implement command line options
+ * that override these, any errors/messages that occur before those
+ * new options are parsed still go to stdout/stderr
+ */
+ global_ulogfd = fileno(stdout);
+ global_uerrfd = fileno(stderr);
+
+ parse_args(&args, argc, argv);
+
+ return app_restart(&args);
+}
+
diff --git a/restart.c b/restart.c
index a9b287d..6ac4647 100644
--- a/restart.c
+++ b/restart.c
@@ -43,42 +43,6 @@
#include "app-checkpoint.h"
#include "common.h"
-static char usage_str[] =
-"usage: restart [opts]\n"
-" restart restores from a checkpoint image by first creating in userspace\n"
-" the original tasks tree, and then calling sys_restart by each task.\n"
-"Options:\n"
-" -h,--help print this help message\n"
-" -p,--pidns create a new pid namspace (default with --pids)\n"
-" -P,--no-pidns do not create a new pid namespace (default)\n"
-" --pids restore original pids (default with --pidns)\n"
-" --self restart a single task, usually from self-checkpoint\n"
-" -r,--root=ROOT restart under the directory ROOT instead of current\n"
-" --signal=SIG send SIG to root task on SIGINT (default: SIGKILL\n"
-" to container root, SIGINT otherwise)\n"
-" --mntns restart under a private mounts namespace\n"
-" --mount-pty start in a new devpts namespace to supprt ptys\n"
-" -w,--wait wait for root task to termiate (default)\n"
-" --show-status show exit status of root task (implies -w)\n"
-" --copy-status imitate exit status of root task (implies -w)\n"
-" -W,--no-wait do not wait for root task to terminate\n"
-" -k,--keeplsm try to recreate original LSM labels on all objects\n"
-" -F,--freezer=CGROUP freeze tasks in freezer group CGROUP on success\n"
-" -i,--input=FILE read data from FILE instead of standard input\n"
-" --input-fd=FD read data from file descriptor FD (instead of stdin)\n"
-" -l,--logfile=FILE write error and debug data to FILE (default=none)\n"
-" --logfile-fd=FD write error and debug data to file desctiptor FD\n"
-" --inspect inspect image on-the-fly for error records\n"
-" -v,--verbose verbose output\n"
-" -d,--debug debugging output\n"
-" --skip-COND skip condition COND, and proceed anyway\n"
-" --warn-COND warn on condition COND, but proceed anyway\n"
-" --fail-COND warn on condition COND, and abort operation\n"
-" COND=any: any condition\n"
-" COND=pidzero: task with sid/pgid zero in a --no-pidns restart\n"
-" COND=mntproc: /proc isn't already mounted at restart (def: warn)\n"
-"";
-
/*
* By default, 'restart' creates a new pid namespace in which the
* restart takes place, using the original pids from the time of the
@@ -117,18 +81,6 @@ static char *sig2str(int sig)
return "UNKNOWN SIGNAL";
}
-static int str2sig(char *str)
-{
- int sig = 0;
-
- do {
- if (!strcmp(signal_array[sig].sigstr, str))
- return signal_array[sig].signum;
- } while (signal_array[++sig].signum >= 0);
-
- return -1;
-}
-
inline static int restart(pid_t pid, int fd, unsigned long flags, int klogfd)
{
return syscall(__NR_restart, pid, fd, flags, klogfd);
@@ -280,46 +232,6 @@ struct pid_swap {
pid_t new;
};
-static void usage(char *str)
-{
- ckpt_err("%s", str);
- exit(1);
-}
-
-/* negative retval means error */
-static int str2num(char *str)
-{
- char *nptr;
- int num;
-
- num = strtol(str, &nptr, 10);
- if (nptr - str != strlen(str))
- num = -1;
- return num;
-}
-
-static long cond_to_mask(const char *cond)
-{
- static struct {
- char *cond;
- long mask;
- } conditions[] = {
- {"pidzero", CKPT_COND_PIDZERO},
- {"mntproc", CKPT_COND_MNTPROC},
- {"any", CKPT_COND_ANY},
- {NULL, 0}
- };
-
- int i;
-
- for (i = 0; conditions[i].cond; i++)
- if (!strcmp(cond, conditions[i].cond))
- return conditions[i].mask;
-
- ckpt_err("restart: invalid warn/fail condition '%s'\n", cond);
- exit(1);
-}
-
static inline int ckpt_cond_warn(struct ckpt_ctx *ctx, long mask)
{
return (ctx->args->warn & mask);
@@ -330,232 +242,6 @@ static inline int ckpt_cond_fail(struct ckpt_ctx *ctx, long mask)
return (ctx->args->fail & mask);
}
-static void parse_args(struct app_restart_args *args, int argc, char *argv[])
-{
- static struct option opts[] = {
- { "help", no_argument, NULL, 'h' },
- { "pidns", no_argument, NULL, 'p' },
- { "no-pidns", no_argument, NULL, 'P' },
- { "pids", no_argument, NULL, 3 },
- { "self", no_argument, NULL, 6},
- { "signal", required_argument, NULL, 4 },
- { "inspect", no_argument, NULL, 5 },
- { "keeplsm", no_argument, NULL, 'k' },
- { "input", required_argument, NULL, 'i' },
- { "input-fd", required_argument, NULL, 7 },
- { "logfile", required_argument, NULL, 'l' },
- { "logfile-fd", required_argument, NULL, 8 },
- { "root", required_argument, NULL, 'r' },
- { "mntns", no_argument, NULL, 11 },
- { "wait", no_argument, NULL, 'w' },
- { "show-status", no_argument, NULL, 1 },
- { "copy-status", no_argument, NULL, 2 },
- { "no-wait", no_argument, NULL, 'W' },
- { "freezer", required_argument, NULL, 'F' },
- { "verbose", no_argument, NULL, 'v' },
- { "debug", no_argument, NULL, 'd' },
- { "warn-pidzero", no_argument, NULL, 9 },
- { "fail-pidzero", no_argument, NULL, 10 },
- { "mount-pty", no_argument, NULL, 12 },
- { NULL, 0, NULL, 0 }
- };
- static char optc[] = "hdvkpPwWF:r:i:l:";
-
- int optind;
- int sig;
- int no_pidns;
-
- char *klogfile;
- char *input;
-
- /* defaults */
- memset(args, 0, sizeof(*args));
- args->wait = 1;
- args->infd = -1;
- args->klogfd = -1;
- args->ulogfd = fileno(stdout);
- args->uerrfd = fileno(stderr);
- args->warn = CKPT_COND_WARN;
- args->fail = CKPT_COND_FAIL;
- args->send_sigint = -1;
- no_pidns = 0;
-
- klogfile = NULL;
- input = NULL;
-
- while (1) {
- int c = getopt_long(argc, argv, optc, opts, &optind);
- if (c == -1)
- break;
- switch (c) {
- case '?':
- exit(1);
- case 'h':
- usage(usage_str);
- case 'v':
- global_verbose = args->verbose = 1;
- break;
- case 5: /* --inspect */
- args->inspect = 1;
- break;
- case 'i':
- input = optarg;
- break;
- case 7:
- args->infd = str2num(optarg);
- if (args->infd < 0) {
- ckpt_err("restart: invalid file descriptor\n");
- exit(1);
- }
- break;
- case 'l':
- klogfile = optarg;
- break;
- case 8:
- args->klogfd = str2num(optarg);
- if (args->klogfd < 0) {
- ckpt_err("restart: invalid file descriptor\n");
- exit(1);
- }
- break;
- case 'p':
- args->pidns = 1;
- break;
- case 'P':
- no_pidns = 1;
- break;
- case 6: /* --self */
- args->self = 1;
- break;
- case 4: /* --signal */
- sig = str2sig(optarg);
- if (sig < 0)
- sig = str2num(optarg);
- if (sig < 0 || sig >= NSIG) {
- ckpt_err("restart: invalid signal\n");
- exit(1);
- }
- args->send_sigint = sig;
- break;
- case 3: /* --pids */
- args->pids = 1;
- args->pidns = 1; /* implied */
- break;
- case 'r':
- args->root = optarg;
- break;
- case 'w':
- args->wait = 1;
- break;
- case 'W':
- args->wait = 0;
- break;
- case 'k':
- args->keep_lsm = 1;
- break;
- case 1: /* --show-status */
- args->wait = 1;
- args->show_status = 1;
- break;
- case 2: /* --copy-status */
- args->wait = 1;
- args->copy_status = 1;
- break;
- case 'd':
- global_debug = args->debug = 1;
- break;
- case 'F':
- args->freezer = optarg;
- break;
- case 9:
- args->warn |= cond_to_mask(&opts[optind].name[5]);
- break;
- case 10:
- args->fail |= cond_to_mask(&opts[optind].name[5]);
- break;
- case 11:
- args->mntns = 1;
- break;
- case 12:
- args->mnt_pty = 1;
- break;
- default:
- usage(usage_str);
- }
- }
-
- if (no_pidns)
- args->pidns = 0;
-
-#ifndef CLONE_NEWPID
- if (args->pidns) {
- ckpt_err("This version of restart was compiled without "
- "support for --pidns.\n");
- exit(1);
- }
-#endif
-
-#ifndef CHECKPOINT_DEBUG
- if (global_debug) {
- ckpt_err("This version of restart was compiled without "
- "support for --debug.\n");
- exit(1);
- }
-#endif
-
- if (args->pidns)
- args->pids = 1;
-
-#if 0 /* Defered until __NR_eclone makes it to standard headers */
-#ifndef __NR_eclone
- if (args->pids) {
- ckpt_err("This version of restart was compiled without "
- "support for --pids.\n");
- exit(1);
- }
-#endif
-#endif
-
- if (args->self &&
- (args->pids || args->pidns || no_pidns ||
- args->show_status || args->copy_status || args->freezer)) {
- ckpt_err("Invalid mix of --self with multiprocess options\n");
- exit(1);
- }
-
- if (input && args->infd >= 0) {
- ckpt_err("Invalid use of both -i/--input and --input-fd\n");
- exit(1);
- }
-
- /* input file ? */
- if (input) {
- args->infd = open(input, O_RDONLY, 0);
- if (args->infd < 0) {
- ckpt_perror("open input file");
- exit(1);
- }
- }
-
- if (klogfile && args->klogfd >= 0) {
- ckpt_err("Invalid use of both -l/--logfile and --logfile-fd\n");
- exit(1);
- }
-
- /* (optional) log file */
- if (klogfile) {
- args->klogfd = open(klogfile, O_RDWR | O_CREAT | O_EXCL, 0644);
- if (args->klogfd < 0) {
- ckpt_perror("open log file");
- exit(1);
- }
- }
-
-
- if (args->mnt_pty)
- args->mntns = 1;
-}
-
static void report_exit_status(int status, char *str, int debug)
{
char msg[64];
@@ -803,24 +489,6 @@ int app_restart(struct app_restart_args *args)
return ret;
}
-int main(int argc, char *argv[])
-{
- struct app_restart_args args;
-
- /*
- * Initialize the log/error fds early so even parse_args() errors
- * are redirected here. Even if we later implement command line options
- * that override these, any errors/messages that occur before those
- * new options are parsed still go to stdout/stderr
- */
- global_ulogfd = fileno(stdout);
- global_uerrfd = fileno(stderr);
-
- parse_args(&args, argc, argv);
-
- return app_restart(&args);
-}
-
static int ckpt_parse_status(int status, int mimic, int verbose)
{
int sig = 0;
--
1.6.0.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 11/12][user-cr] checkpoint: Move main() to checkpoint-main.c
[not found] ` <20100305223439.GA15300-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
` (9 preceding siblings ...)
2010-03-05 22:39 ` [PATCH 10/12][user-cr] restart: Move main() to restart-main.c Sukadev Bhattiprolu
@ 2010-03-05 22:40 ` Sukadev Bhattiprolu
2010-03-05 22:40 ` [PATCH 12/12][user-cr] Have app_restart() return pid Sukadev Bhattiprolu
2010-03-08 19:49 ` [PATCH 0/12][user-cr]: Second set of cleanups Serge E. Hallyn
12 siblings, 0 replies; 19+ messages in thread
From: Sukadev Bhattiprolu @ 2010-03-05 22:40 UTC (permalink / raw)
To: Oren Laadan; +Cc: sukadev-6JnAsaTVvkgX0ybBhKVfKdBPR1lH4CV8, Containers
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Thu, 4 Mar 2010 22:28:34 -0800
Subject: [PATCH 11/12][user-cr] checkpoint: Move main() to checkpoint-main.c
---
Makefile | 4 +-
checkpoint-main.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++
checkpoint.c | 157 ------------------------------------------------
3 files changed, 174 insertions(+), 158 deletions(-)
create mode 100644 checkpoint-main.c
diff --git a/Makefile b/Makefile
index 8a91d10..e520425 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ CKPT_HEADERS = include/linux/checkpoint.h \
include/linux/checkpoint_hdr.h \
include/asm/checkpoint_hdr.h
-CR_OBJS = checkpoint.o restart.o restart-main.o
+CR_OBJS = checkpoint.o checkpoint-main.o restart.o restart-main.o
# detect architecture (for eclone)
SUBARCH = $(patsubst i%86,x86_32,$(shell uname -m))
@@ -47,6 +47,8 @@ $(CR_OBJS): common.h app-checkpoint.h
restart: restart.o restart-main.o
+checkpoint: checkpoint.o checkpoint-main.o
+
# eclone() is architecture specific
ifneq ($(SUBARCH),)
$(ECLONE_PROGS): $(LIB_ECLONE)
diff --git a/checkpoint-main.c b/checkpoint-main.c
new file mode 100644
index 0000000..f6faa32
--- /dev/null
+++ b/checkpoint-main.c
@@ -0,0 +1,171 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <getopt.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <linux/checkpoint.h>
+
+#include "app-checkpoint.h"
+#include "common.h"
+
+static int global_uerrfd = -1;
+
+static char usage_str[] =
+"usage: ckpt [opts] PID\n"
+" 'checkpoint' takes a checkpoint of the task indicated by PID, and all\n"
+" its descendents, and outputs the checkpoint image. If the task is the\n"
+" init(1) process of a container, it checkpoints the entire container.\n"
+" By default 'checkpoint' allows to checkpoint any subtree of tasks. The\n"
+" user can override this feature and request that only whole containers\n"
+" be considered.\n"
+"\n"
+"\tOptions:\n"
+" -h,--help print this help message\n"
+" -o,--output=FILE write data to FILE instead of standard output\n"
+" --output-fd=FD write data to file descriptor FD instead of stdout\n"
+" -l,--logfile=FILE write error and debug data to FILE (default=none)\n"
+" --logile-fd=FD write error and debug data to file descriptor FD\n"
+" -c,--container require the PID is a container-init\n"
+" -v,--verbose verbose output\n"
+"";
+
+static void usage(char *str)
+{
+ ckpt_err("%s", str);
+ exit(1);
+}
+
+/* negative retval means error */
+static int str2num(char *str)
+{
+ char *nptr;
+ int num;
+
+ num = strtol(str, &nptr, 10);
+ if (nptr - str != strlen(str))
+ num = -1;
+ return num;
+}
+
+static void parse_args(struct app_checkpoint_args *args, int argc, char *argv[])
+{
+ static struct option opts[] = {
+ { "help", no_argument, NULL, 'h' },
+ { "output", required_argument, NULL, 'o' },
+ { "output-fd", required_argument, NULL, 1 },
+ { "logfile", required_argument, NULL, 'l' },
+ { "logfile-fd", required_argument, NULL, 2 },
+ { "container", no_argument, NULL, 'c' },
+ { "verbose", no_argument, NULL, 'v' },
+ { NULL, 0, NULL, 0 }
+ };
+ static char optc[] = "hvco:l:";
+ char *output;
+ char *logfile;
+
+ /* defaults */
+ args->outfd = -1;
+ args->logfd = -1;
+ args->uerrfd = fileno(stderr);
+ output = NULL;
+ logfile = NULL;
+
+ while (1) {
+ int c = getopt_long(argc, argv, optc, opts, NULL);
+ if (c == -1)
+ break;
+ switch (c) {
+ case '?':
+ exit(1);
+ case 'h':
+ usage(usage_str);
+ case 'o':
+ output = optarg;
+ break;
+ case 1:
+ args->outfd = str2num(optarg);
+ if (args->outfd < 0) {
+ ckpt_err("checkpoint: invalid file descriptor\n");
+ exit(1);
+ }
+ break;
+ case 'l':
+ logfile = optarg;
+ break;
+ case 2:
+ args->logfd = str2num(optarg);
+ if (args->logfd < 0) {
+ ckpt_err("checkpoint: invalid file descriptor\n");
+ exit(1);
+ }
+ break;
+ case 'c':
+ args->container = 1;
+ break;
+ case 'v':
+ args->verbose = 1;
+ break;
+ default:
+ usage(usage_str);
+ }
+ }
+
+ if (output && args->outfd >= 0) {
+ ckpt_err("Invalid use of both -o/--output and --output-fd\n");
+ exit(1);
+ }
+
+ /* output file */
+ if (output) {
+ args->outfd = open(output, O_RDWR | O_CREAT | O_EXCL, 0644);
+ if (args->outfd < 0) {
+ ckpt_perror("open output file");
+ exit(1);
+ }
+ }
+
+ if (logfile && args->logfd >= 0) {
+ ckpt_err("Invalid use of both -l/--logfile and --logfile-fd\n");
+ exit(1);
+ }
+
+ /* (optional) log file */
+ if (logfile) {
+ args->logfd = open(logfile, O_RDWR | O_CREAT | O_EXCL, 0644);
+ if (args->logfd < 0) {
+ ckpt_perror("open log file");
+ exit(1);
+ }
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ struct app_checkpoint_args args;
+ unsigned long flags = 0;
+ pid_t pid;
+
+ global_uerrfd = fileno(stderr);
+
+ memset(&args, 0, sizeof(args));
+ parse_args(&args, argc, argv);
+
+ argc -= optind;
+ if (argc != 1)
+ usage(usage_str);
+
+ pid = atoi(argv[optind]);
+ if (pid <= 0) {
+ ckpt_err("invalid pid\n");
+ exit(1);
+ }
+
+ if (!args.container)
+ flags |= CHECKPOINT_SUBTREE;
+
+ return app_checkpoint(pid, flags, &args);
+}
diff --git a/checkpoint.c b/checkpoint.c
index 291cb36..e3a1ce8 100644
--- a/checkpoint.c
+++ b/checkpoint.c
@@ -24,25 +24,6 @@
#include "app-checkpoint.h"
#include "common.h"
-static char usage_str[] =
-"usage: ckpt [opts] PID\n"
-" 'checkpoint' takes a checkpoint of the task indicated by PID, and all\n"
-" its descendents, and outputs the checkpoint image. If the task is the\n"
-" init(1) process of a container, it checkpoints the entire container.\n"
-" By default 'checkpoint' allows to checkpoint any subtree of tasks. The\n"
-" user can override this feature and request that only whole containers\n"
-" be considered.\n"
-"\n"
-"\tOptions:\n"
-" -h,--help print this help message\n"
-" -o,--output=FILE write data to FILE instead of standard output\n"
-" --output-fd=FD write data to file descriptor FD instead of stdout\n"
-" -l,--logfile=FILE write error and debug data to FILE (default=none)\n"
-" --logile-fd=FD write error and debug data to file descriptor FD\n"
-" -c,--container require the PID is a container-init\n"
-" -v,--verbose verbose output\n"
-"";
-
static int global_uerrfd = -1;
inline static int checkpoint(pid_t pid, int fd, unsigned long flags, int logfd)
@@ -50,116 +31,6 @@ inline static int checkpoint(pid_t pid, int fd, unsigned long flags, int logfd)
return syscall(__NR_checkpoint, pid, fd, flags, logfd);
}
-static void usage(char *str)
-{
- ckpt_err("%s", str);
- exit(1);
-}
-
-/* negative retval means error */
-static int str2num(char *str)
-{
- char *nptr;
- int num;
-
- num = strtol(str, &nptr, 10);
- if (nptr - str != strlen(str))
- num = -1;
- return num;
-}
-
-static void parse_args(struct app_checkpoint_args *args, int argc, char *argv[])
-{
- static struct option opts[] = {
- { "help", no_argument, NULL, 'h' },
- { "output", required_argument, NULL, 'o' },
- { "output-fd", required_argument, NULL, 1 },
- { "logfile", required_argument, NULL, 'l' },
- { "logfile-fd", required_argument, NULL, 2 },
- { "container", no_argument, NULL, 'c' },
- { "verbose", no_argument, NULL, 'v' },
- { NULL, 0, NULL, 0 }
- };
- static char optc[] = "hvco:l:";
- char *output;
- char *logfile;
-
- /* defaults */
- args->outfd = -1;
- args->logfd = -1;
- args->uerrfd = fileno(stderr);
- output = NULL;
- logfile = NULL;
-
- while (1) {
- int c = getopt_long(argc, argv, optc, opts, NULL);
- if (c == -1)
- break;
- switch (c) {
- case '?':
- exit(1);
- case 'h':
- usage(usage_str);
- case 'o':
- output = optarg;
- break;
- case 1:
- args->outfd = str2num(optarg);
- if (args->outfd < 0) {
- ckpt_err("checkpoint: invalid file descriptor\n");
- exit(1);
- }
- break;
- case 'l':
- logfile = optarg;
- break;
- case 2:
- args->logfd = str2num(optarg);
- if (args->logfd < 0) {
- ckpt_err("checkpoint: invalid file descriptor\n");
- exit(1);
- }
- break;
- case 'c':
- args->container = 1;
- break;
- case 'v':
- args->verbose = 1;
- break;
- default:
- usage(usage_str);
- }
- }
-
- if (output && args->outfd >= 0) {
- ckpt_err("Invalid use of both -o/--output and --output-fd\n");
- exit(1);
- }
-
- /* output file */
- if (output) {
- args->outfd = open(output, O_RDWR | O_CREAT | O_EXCL, 0644);
- if (args->outfd < 0) {
- ckpt_perror("open output file");
- exit(1);
- }
- }
-
- if (logfile && args->logfd >= 0) {
- ckpt_err("Invalid use of both -l/--logfile and --logfile-fd\n");
- exit(1);
- }
-
- /* (optional) log file */
- if (logfile) {
- args->logfd = open(logfile, O_RDWR | O_CREAT | O_EXCL, 0644);
- if (args->logfd < 0) {
- ckpt_perror("open log file");
- exit(1);
- }
- }
-}
-
int app_checkpoint(int pid, unsigned long flags,
struct app_checkpoint_args *args)
{
@@ -186,31 +57,3 @@ int app_checkpoint(int pid, unsigned long flags,
return (ret > 0 ? 0 : 1);
}
-
-int main(int argc, char *argv[])
-{
- struct app_checkpoint_args args;
- unsigned long flags = 0;
- pid_t pid;
-
- global_uerrfd = fileno(stderr);
-
- memset(&args, 0, sizeof(args));
- parse_args(&args, argc, argv);
-
- argc -= optind;
- if (argc != 1)
- usage(usage_str);
-
- pid = atoi(argv[optind]);
- if (pid <= 0) {
- ckpt_err("invalid pid\n");
- exit(1);
- }
-
- if (!args.container)
- flags |= CHECKPOINT_SUBTREE;
-
- return app_checkpoint(pid, flags, &args);
-}
-
--
1.6.0.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* [PATCH 12/12][user-cr] Have app_restart() return pid
[not found] ` <20100305223439.GA15300-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
` (10 preceding siblings ...)
2010-03-05 22:40 ` [PATCH 11/12][user-cr] checkpoint: Move main() to checkpoint-main.c Sukadev Bhattiprolu
@ 2010-03-05 22:40 ` Sukadev Bhattiprolu
2010-03-08 19:49 ` [PATCH 0/12][user-cr]: Second set of cleanups Serge E. Hallyn
12 siblings, 0 replies; 19+ messages in thread
From: Sukadev Bhattiprolu @ 2010-03-05 22:40 UTC (permalink / raw)
To: Oren Laadan; +Cc: Containers
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Fri, 5 Mar 2010 10:24:53 -0800
Subject: [PATCH 12/12][user-cr] Have app_restart() return pid
On success, return the pid of a the root of the restarted process tree.
This would enable callers to manage the restarted process-tree as a cgroup.
Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
restart-main.c | 7 ++++++-
restart.c | 6 ++++++
2 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/restart-main.c b/restart-main.c
index 96bca42..39ab05a 100644
--- a/restart-main.c
+++ b/restart-main.c
@@ -333,6 +333,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
int main(int argc, char *argv[])
{
+ int ret;
struct app_restart_args args;
/*
@@ -346,6 +347,10 @@ int main(int argc, char *argv[])
parse_args(&args, argc, argv);
- return app_restart(&args);
+ ret = app_restart(&args);
+ if (ret > 0)
+ ret = 0;
+
+ return ret;
}
diff --git a/restart.c b/restart.c
index 6ac4647..7ea3732 100644
--- a/restart.c
+++ b/restart.c
@@ -486,6 +486,12 @@ int app_restart(struct app_restart_args *args)
ret = ckpt_coordinator(&ctx);
}
+ /*
+ * On success, return pid of root of the restart process tree.
+ */
+ if (ret >= 0)
+ ret = global_child_pid;
+
return ret;
}
--
1.6.0.4
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH 03/12][user-cr] Add app_restart_args->debug
[not found] ` <20100305223723.GC15939-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
@ 2010-03-08 19:39 ` Serge E. Hallyn
[not found] ` <20100308193929.GA20030-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 19+ messages in thread
From: Serge E. Hallyn @ 2010-03-08 19:39 UTC (permalink / raw)
To: Sukadev Bhattiprolu; +Cc: Containers
Quoting Sukadev Bhattiprolu (sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org):
>
> From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
> Date: Thu, 4 Mar 2010 17:46:31 -0800
> Subject: [PATCH 03/12][user-cr] Add app_restart_args->debug
>
> Make 'debug' a field in struct app_restart_args so other callers of
> app_restart() can also control the debug output of app_restart().
>
> Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
> ---
> restart.c | 4 +++-
> 1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/restart.c b/restart.c
> index 314390c..87fff1e 100644
> --- a/restart.c
> +++ b/restart.c
> @@ -387,6 +387,7 @@ struct app_restart_args {
> int infd;
> int klogfd;
> long warn;
> + int debug;
> long fail;
> int keep_lsm;
> };
> @@ -583,7 +584,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
> args->copy_status = 1;
> break;
> case 'd':
> - global_debug = 1;
> + global_debug = args->debug = 1;
You don't actually need to also set global_debug here, right?
> break;
> case 'F':
> args->freezer = optarg;
> @@ -818,6 +819,7 @@ int app_restart(struct app_restart_args *args)
> ctx.args = args;
>
> global_send_sigint = args->send_sigint;
> + global_debug = args->debug;
>
> /* input file descriptor (default: stdin) */
> if (args->infd >= 0) {
> --
> 1.6.0.4
>
> _______________________________________________
> Containers mailing list
> Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
> https://lists.linux-foundation.org/mailman/listinfo/containers
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 08/12][user-cr] Create common.h
[not found] ` <20100305223907.GH15939-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
@ 2010-03-08 19:44 ` Serge E. Hallyn
[not found] ` <20100308194427.GB20030-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 19+ messages in thread
From: Serge E. Hallyn @ 2010-03-08 19:44 UTC (permalink / raw)
To: Sukadev Bhattiprolu; +Cc: Containers
Quoting Sukadev Bhattiprolu (sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org):
>
> From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
> Date: Thu, 4 Mar 2010 21:30:50 -0800
> Subject: [PATCH 08/12][user-cr] Create common.h
>
> Code in common.h can be shared by checkpoint.c and restart.c for now.
There is already user-cr.h and restart.h... a 'common.h' filename
isn't particularly helpful. Should they all get combined?
Not NACking the patch, btw, just something to consider for a future
patch.
> Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
> ---
> Makefile | 4 ++
> checkpoint.c | 31 +---------------
> common.h | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> restart.c | 110 +--------------------------------------------------------
> 4 files changed, 119 insertions(+), 138 deletions(-)
> create mode 100644 common.h
>
> diff --git a/Makefile b/Makefile
> index b312358..acebdd5 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -5,6 +5,8 @@ CKPT_HEADERS = include/linux/checkpoint.h \
> include/linux/checkpoint_hdr.h \
> include/asm/checkpoint_hdr.h
>
> +CR_OBJS = checkpoint.o restart.o
> +
> # detect architecture (for eclone)
> SUBARCH = $(patsubst i%86,x86_32,$(shell uname -m))
>
> @@ -41,6 +43,8 @@ $(LIB_ECLONE):
> # restart needs to be thread-safe
> restart: CFLAGS += -D__REENTRANT -pthread
>
> +$(CR_OBJS): common.h
> +
> # eclone() is architecture specific
> ifneq ($(SUBARCH),)
> $(ECLONE_PROGS): $(LIB_ECLONE)
> diff --git a/checkpoint.c b/checkpoint.c
> index ace17e2..6e91149 100644
> --- a/checkpoint.c
> +++ b/checkpoint.c
> @@ -21,6 +21,8 @@
>
> #include <linux/checkpoint.h>
>
> +#include "common.h"
> +
> static char usage_str[] =
> "usage: ckpt [opts] PID\n"
> " 'checkpoint' takes a checkpoint of the task indicated by PID, and all\n"
> @@ -55,35 +57,6 @@ inline static int checkpoint(pid_t pid, int fd, unsigned long flags, int logfd)
> return syscall(__NR_checkpoint, pid, fd, flags, logfd);
> }
>
> -#define BUFSIZE (4 * 4096)
> -static inline void ckpt_msg(int fd, char *format, ...)
> -{
> - va_list ap;
> - char *bufp;
> - if (fd < 0)
> - return;
> -
> - va_start(ap, format);
> -
> - bufp = malloc(BUFSIZE);
> - if(bufp) {
> - vsnprintf(bufp, BUFSIZE, format, ap);
> - write(fd, bufp, strlen(bufp));
> - }
> - free(bufp);
> -
> - va_end(ap);
> -}
> -
> -#define ckpt_err(...) \
> - ckpt_msg(global_uerrfd, __VA_ARGS__)
> -
> -#define ckpt_perror(s) \
> - do { \
> - ckpt_msg(global_uerrfd, s); \
> - ckpt_msg(global_uerrfd, ": %s\n", strerror(errno)); \
> - } while (0)
> -
> static void usage(char *str)
> {
> ckpt_err("%s", str);
> diff --git a/common.h b/common.h
> new file mode 100644
> index 0000000..99b224d
> --- /dev/null
> +++ b/common.h
> @@ -0,0 +1,112 @@
> +#include <stdio.h>
> +#include <signal.h>
> +
> +#define BUFSIZE (4 * 4096)
> +
> +static inline void ckpt_msg(int fd, char *format, ...)
> +{
> + va_list ap;
> + char *bufp;
> + if (fd < 0)
> + return;
> +
> + va_start(ap, format);
> +
> + bufp = malloc(BUFSIZE);
> + if(bufp) {
> + vsnprintf(bufp, BUFSIZE, format, ap);
> + write(fd, bufp, strlen(bufp));
> + }
> + free(bufp);
> +
> + va_end(ap);
> +}
> +
> +#define ckpt_perror(s) \
> + do { \
> + ckpt_msg(global_uerrfd, s); \
> + ckpt_msg(global_uerrfd, ": %s\n", strerror(errno)); \
> + } while (0)
> +
> +#ifdef CHECKPOINT_DEBUG
> +#define ckpt_dbg(_format, _args...) \
> + do { \
> + if (global_debug) \
> + ckpt_msg(global_uerrfd, "<%d>" _format, \
> + _gettid(), ##_args); \
> + } while (0)
> +#define ckpt_dbg_cont(_format, _args...) \
> + do { \
> + if (global_debug) \
> + ckpt_msg(global_uerrfd, _format, ##_args); \
> + } while (0)
> +#else
> +#define ckpt_dbg(_format, _args...) \
> + do { } while (0)
> +#define ckpt_dbg_cont(_format, _args...) \
> + do { } while (0)
> +#endif
> +
> +#define ckpt_err(...) \
> + ckpt_msg(global_uerrfd, __VA_ARGS__)
> +
> +#define ckpt_verbose(...) \
> + do { \
> + if (global_verbose) \
> + ckpt_msg(global_ulogfd, __VA_ARGS__); \
> + } while(0)
> +
> +struct signal_array {
> + int signum;
> + char *sigstr;
> +};
> +
> +#define SIGNAL_ENTRY(signal) { SIG ## signal, #signal }
> +
> +#define INIT_SIGNAL_ARRAY { \
> + { 0, "NONE" }, \
> + SIGNAL_ENTRY(ALRM), \
> + SIGNAL_ENTRY(HUP), \
> + SIGNAL_ENTRY(INT), \
> + SIGNAL_ENTRY(KILL), \
> + SIGNAL_ENTRY(PIPE), \
> + SIGNAL_ENTRY(POLL), \
> + SIGNAL_ENTRY(PROF), \
> + SIGNAL_ENTRY(TERM), \
> + SIGNAL_ENTRY(USR1), \
> + SIGNAL_ENTRY(USR2), \
> + SIGNAL_ENTRY(VTALRM), \
> + SIGNAL_ENTRY(STKFLT), \
> + SIGNAL_ENTRY(PWR), \
> + SIGNAL_ENTRY(WINCH), \
> + SIGNAL_ENTRY(CHLD), \
> + SIGNAL_ENTRY(URG), \
> + SIGNAL_ENTRY(TTIN), \
> + SIGNAL_ENTRY(TTOU), \
> + SIGNAL_ENTRY(STOP), \
> + SIGNAL_ENTRY(CONT), \
> + SIGNAL_ENTRY(ABRT), \
> + SIGNAL_ENTRY(FPE), \
> + SIGNAL_ENTRY(ILL), \
> + SIGNAL_ENTRY(QUIT), \
> + SIGNAL_ENTRY(SEGV), \
> + SIGNAL_ENTRY(TRAP), \
> + SIGNAL_ENTRY(SYS), \
> + SIGNAL_ENTRY(BUS), \
> + SIGNAL_ENTRY(XCPU), \
> + SIGNAL_ENTRY(XFSZ), \
> + { -1, "LAST" }, \
> +}
> +
> +#define CKPT_COND_PIDZERO 0x1
> +#define CKPT_COND_MNTPROC 0x2
> +#define CKPT_COND_MNTPTY 0x4
> +
> +#define CKPT_COND_NONE 0
> +#define CKPT_COND_ANY ULONG_MAX
> +
> +/* default for skip/warn/fail */
> +#define CKPT_COND_WARN (CKPT_COND_MNTPROC | \
> + CKPT_COND_MNTPTY)
> +#define CKPT_COND_FAIL (CKPT_COND_NONE)
> +
> diff --git a/restart.c b/restart.c
> index b37bf81..f65eafb 100644
> --- a/restart.c
> +++ b/restart.c
> @@ -40,6 +40,7 @@
> #include "eclone.h"
> #include "genstack.h"
> #include "compat.h"
> +#include "common.h"
>
> static char usage_str[] =
> "usage: restart [opts]\n"
> @@ -102,103 +103,6 @@ static char usage_str[] =
> * of the checkpoint image stream.
> */
>
> -#define BUFSIZE (4 * 4096)
> -
> -static inline void ckpt_msg(int fd, char *format, ...)
> -{
> - va_list ap;
> - char *bufp;
> - if (fd < 0)
> - return;
> -
> - va_start(ap, format);
> -
> - bufp = malloc(BUFSIZE);
> - if(bufp) {
> - vsnprintf(bufp, BUFSIZE, format, ap);
> - write(fd, bufp, strlen(bufp));
> - }
> - free(bufp);
> -
> - va_end(ap);
> -}
> -
> -#define ckpt_perror(s) \
> - do { \
> - ckpt_msg(global_uerrfd, s); \
> - ckpt_msg(global_uerrfd, ": %s\n", strerror(errno)); \
> - } while (0)
> -
> -#ifdef CHECKPOINT_DEBUG
> -#define ckpt_dbg(_format, _args...) \
> - do { \
> - if (global_debug) \
> - ckpt_msg(global_uerrfd, "<%d>" _format, \
> - _gettid(), ##_args); \
> - } while (0)
> -#define ckpt_dbg_cont(_format, _args...) \
> - do { \
> - if (global_debug) \
> - ckpt_msg(global_uerrfd, _format, ##_args); \
> - } while (0)
> -#else
> -#define ckpt_dbg(_format, _args...) \
> - do { } while (0)
> -#define ckpt_dbg_cont(_format, _args...) \
> - do { } while (0)
> -#endif
> -
> -#define ckpt_err(...) \
> - ckpt_msg(global_uerrfd, __VA_ARGS__)
> -
> -#define ckpt_verbose(...) \
> - do { \
> - if (global_verbose) \
> - ckpt_msg(global_ulogfd, __VA_ARGS__); \
> - } while(0)
> -
> -struct signal_array {
> - int signum;
> - char *sigstr;
> -};
> -
> -#define SIGNAL_ENTRY(signal) { SIG ## signal, #signal }
> -
> -#define INIT_SIGNAL_ARRAY { \
> - { 0, "NONE" }, \
> - SIGNAL_ENTRY(ALRM), \
> - SIGNAL_ENTRY(HUP), \
> - SIGNAL_ENTRY(INT), \
> - SIGNAL_ENTRY(KILL), \
> - SIGNAL_ENTRY(PIPE), \
> - SIGNAL_ENTRY(POLL), \
> - SIGNAL_ENTRY(PROF), \
> - SIGNAL_ENTRY(TERM), \
> - SIGNAL_ENTRY(USR1), \
> - SIGNAL_ENTRY(USR2), \
> - SIGNAL_ENTRY(VTALRM), \
> - SIGNAL_ENTRY(STKFLT), \
> - SIGNAL_ENTRY(PWR), \
> - SIGNAL_ENTRY(WINCH), \
> - SIGNAL_ENTRY(CHLD), \
> - SIGNAL_ENTRY(URG), \
> - SIGNAL_ENTRY(TTIN), \
> - SIGNAL_ENTRY(TTOU), \
> - SIGNAL_ENTRY(STOP), \
> - SIGNAL_ENTRY(CONT), \
> - SIGNAL_ENTRY(ABRT), \
> - SIGNAL_ENTRY(FPE), \
> - SIGNAL_ENTRY(ILL), \
> - SIGNAL_ENTRY(QUIT), \
> - SIGNAL_ENTRY(SEGV), \
> - SIGNAL_ENTRY(TRAP), \
> - SIGNAL_ENTRY(SYS), \
> - SIGNAL_ENTRY(BUS), \
> - SIGNAL_ENTRY(XCPU), \
> - SIGNAL_ENTRY(XFSZ), \
> - { -1, "LAST" }, \
> -}
> -
> static struct signal_array signal_array[] = INIT_SIGNAL_ARRAY;
>
> static char *sig2str(int sig)
> @@ -399,18 +303,6 @@ struct app_restart_args {
> int keep_lsm;
> };
>
> -#define CKPT_COND_PIDZERO 0x1
> -#define CKPT_COND_MNTPROC 0x2
> -#define CKPT_COND_MNTPTY 0x4
> -
> -#define CKPT_COND_NONE 0
> -#define CKPT_COND_ANY ULONG_MAX
> -
> -/* default for skip/warn/fail */
> -#define CKPT_COND_WARN (CKPT_COND_MNTPROC | \
> - CKPT_COND_MNTPTY)
> -#define CKPT_COND_FAIL (CKPT_COND_NONE)
> -
> static void usage(char *str)
> {
> ckpt_err("%s", str);
> --
> 1.6.0.4
>
> _______________________________________________
> Containers mailing list
> Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
> https://lists.linux-foundation.org/mailman/listinfo/containers
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 0/12][user-cr]: Second set of cleanups
[not found] ` <20100305223439.GA15300-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
` (11 preceding siblings ...)
2010-03-05 22:40 ` [PATCH 12/12][user-cr] Have app_restart() return pid Sukadev Bhattiprolu
@ 2010-03-08 19:49 ` Serge E. Hallyn
12 siblings, 0 replies; 19+ messages in thread
From: Serge E. Hallyn @ 2010-03-08 19:49 UTC (permalink / raw)
To: Sukadev Bhattiprolu; +Cc: Containers, sukadev-6JnAsaTVvkgX0ybBhKVfKdBPR1lH4CV8
Quoting Sukadev Bhattiprolu (sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org):
>
> Second set of cleanup patches. With these patches, LXC will be able
> to compile/link directly using restart.o and app-checkpoint.h from
> the user-cr directory. Something like:
>
> USER_CR=/home/suka/user-cr make lxc_restart
>
> After having more detailed discussions on the API, we could install
> restart.o in /lib/libcheckpoint.a and app-checkpoint.h in /usr/include.
>
> [PATCH 01/12][user-cr] restart: Mark globals as static
> [PATCH 02/12][user-cr] restart: Add args->send_sigint
> [PATCH 03/12][user-cr] Add app_restart_args->debug
> [PATCH 04/12][user-cr] Add app_restart_args->verbose
> [PATCH 05/12][user-cr] Add app_restart_args->ulogfd
> [PATCH 06/12][user-cr] Add app_restart_args->uerrfd
> [PATCH 07/12][user-cr] Define INIT_SIGNAL_ARRAY
> [PATCH 08/12][user-cr] Create common.h
> [PATCH 09/12][user-cr] Create app-checkpoint.h
> [PATCH 10/12][user-cr] restart: Move main() to restart-main.c
> [PATCH 11/12][user-cr] checkpoint: Move main() to checkpoint-main.c
> [PATCH 12/12][user-cr] Have app_restart() return pid
>
> Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Again, not yet tested (though will do that soon as I will base my
mounts c/r patchset on ckpt-v19-suka), but looks good, thanks.
Acked-by: Serge Hallyn <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
-serge
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 08/12][user-cr] Create common.h
[not found] ` <20100308194427.GB20030-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
@ 2010-03-08 20:22 ` Sukadev Bhattiprolu
0 siblings, 0 replies; 19+ messages in thread
From: Sukadev Bhattiprolu @ 2010-03-08 20:22 UTC (permalink / raw)
To: Serge E. Hallyn; +Cc: Containers
Serge E. Hallyn [serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org] wrote:
| Quoting Sukadev Bhattiprolu (sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org):
| >
| > From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
| > Date: Thu, 4 Mar 2010 21:30:50 -0800
| > Subject: [PATCH 08/12][user-cr] Create common.h
| >
| > Code in common.h can be shared by checkpoint.c and restart.c for now.
|
| There is already user-cr.h and restart.h... a 'common.h' filename
| isn't particularly helpful. Should they all get combined?
Hmm, there should be no 'restart.h' in this version of the patchset.
restart.h from previous version is now common.h (since some definitions
apply to checkpoint.c) and is internal to user-cr.
I renamed usercr.h to "app-checkpoint.h" for now, but don't particularly
like either name :-). This file presents the external API to user-cr.
|
| Not NACking the patch, btw, just something to consider for a future
| patch.
|
Thanks for the review. If you test with /bin/restart, you should see
no problems. If you plan to test with LXC, let me know - I will need
to send you couple of patches to USER-CR and couple of patches (under
development) for LXC.
| > Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
| > ---
| > Makefile | 4 ++
| > checkpoint.c | 31 +---------------
| > common.h | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| > restart.c | 110 +--------------------------------------------------------
| > 4 files changed, 119 insertions(+), 138 deletions(-)
| > create mode 100644 common.h
| >
| > diff --git a/Makefile b/Makefile
| > index b312358..acebdd5 100644
| > --- a/Makefile
| > +++ b/Makefile
| > @@ -5,6 +5,8 @@ CKPT_HEADERS = include/linux/checkpoint.h \
| > include/linux/checkpoint_hdr.h \
| > include/asm/checkpoint_hdr.h
| >
| > +CR_OBJS = checkpoint.o restart.o
| > +
| > # detect architecture (for eclone)
| > SUBARCH = $(patsubst i%86,x86_32,$(shell uname -m))
| >
| > @@ -41,6 +43,8 @@ $(LIB_ECLONE):
| > # restart needs to be thread-safe
| > restart: CFLAGS += -D__REENTRANT -pthread
| >
| > +$(CR_OBJS): common.h
| > +
| > # eclone() is architecture specific
| > ifneq ($(SUBARCH),)
| > $(ECLONE_PROGS): $(LIB_ECLONE)
| > diff --git a/checkpoint.c b/checkpoint.c
| > index ace17e2..6e91149 100644
| > --- a/checkpoint.c
| > +++ b/checkpoint.c
| > @@ -21,6 +21,8 @@
| >
| > #include <linux/checkpoint.h>
| >
| > +#include "common.h"
| > +
| > static char usage_str[] =
| > "usage: ckpt [opts] PID\n"
| > " 'checkpoint' takes a checkpoint of the task indicated by PID, and all\n"
| > @@ -55,35 +57,6 @@ inline static int checkpoint(pid_t pid, int fd, unsigned long flags, int logfd)
| > return syscall(__NR_checkpoint, pid, fd, flags, logfd);
| > }
| >
| > -#define BUFSIZE (4 * 4096)
| > -static inline void ckpt_msg(int fd, char *format, ...)
| > -{
| > - va_list ap;
| > - char *bufp;
| > - if (fd < 0)
| > - return;
| > -
| > - va_start(ap, format);
| > -
| > - bufp = malloc(BUFSIZE);
| > - if(bufp) {
| > - vsnprintf(bufp, BUFSIZE, format, ap);
| > - write(fd, bufp, strlen(bufp));
| > - }
| > - free(bufp);
| > -
| > - va_end(ap);
| > -}
| > -
| > -#define ckpt_err(...) \
| > - ckpt_msg(global_uerrfd, __VA_ARGS__)
| > -
| > -#define ckpt_perror(s) \
| > - do { \
| > - ckpt_msg(global_uerrfd, s); \
| > - ckpt_msg(global_uerrfd, ": %s\n", strerror(errno)); \
| > - } while (0)
| > -
| > static void usage(char *str)
| > {
| > ckpt_err("%s", str);
| > diff --git a/common.h b/common.h
| > new file mode 100644
| > index 0000000..99b224d
| > --- /dev/null
| > +++ b/common.h
| > @@ -0,0 +1,112 @@
| > +#include <stdio.h>
| > +#include <signal.h>
| > +
| > +#define BUFSIZE (4 * 4096)
| > +
| > +static inline void ckpt_msg(int fd, char *format, ...)
| > +{
| > + va_list ap;
| > + char *bufp;
| > + if (fd < 0)
| > + return;
| > +
| > + va_start(ap, format);
| > +
| > + bufp = malloc(BUFSIZE);
| > + if(bufp) {
| > + vsnprintf(bufp, BUFSIZE, format, ap);
| > + write(fd, bufp, strlen(bufp));
| > + }
| > + free(bufp);
| > +
| > + va_end(ap);
| > +}
| > +
| > +#define ckpt_perror(s) \
| > + do { \
| > + ckpt_msg(global_uerrfd, s); \
| > + ckpt_msg(global_uerrfd, ": %s\n", strerror(errno)); \
| > + } while (0)
| > +
| > +#ifdef CHECKPOINT_DEBUG
| > +#define ckpt_dbg(_format, _args...) \
| > + do { \
| > + if (global_debug) \
| > + ckpt_msg(global_uerrfd, "<%d>" _format, \
| > + _gettid(), ##_args); \
| > + } while (0)
| > +#define ckpt_dbg_cont(_format, _args...) \
| > + do { \
| > + if (global_debug) \
| > + ckpt_msg(global_uerrfd, _format, ##_args); \
| > + } while (0)
| > +#else
| > +#define ckpt_dbg(_format, _args...) \
| > + do { } while (0)
| > +#define ckpt_dbg_cont(_format, _args...) \
| > + do { } while (0)
| > +#endif
| > +
| > +#define ckpt_err(...) \
| > + ckpt_msg(global_uerrfd, __VA_ARGS__)
| > +
| > +#define ckpt_verbose(...) \
| > + do { \
| > + if (global_verbose) \
| > + ckpt_msg(global_ulogfd, __VA_ARGS__); \
| > + } while(0)
| > +
| > +struct signal_array {
| > + int signum;
| > + char *sigstr;
| > +};
| > +
| > +#define SIGNAL_ENTRY(signal) { SIG ## signal, #signal }
| > +
| > +#define INIT_SIGNAL_ARRAY { \
| > + { 0, "NONE" }, \
| > + SIGNAL_ENTRY(ALRM), \
| > + SIGNAL_ENTRY(HUP), \
| > + SIGNAL_ENTRY(INT), \
| > + SIGNAL_ENTRY(KILL), \
| > + SIGNAL_ENTRY(PIPE), \
| > + SIGNAL_ENTRY(POLL), \
| > + SIGNAL_ENTRY(PROF), \
| > + SIGNAL_ENTRY(TERM), \
| > + SIGNAL_ENTRY(USR1), \
| > + SIGNAL_ENTRY(USR2), \
| > + SIGNAL_ENTRY(VTALRM), \
| > + SIGNAL_ENTRY(STKFLT), \
| > + SIGNAL_ENTRY(PWR), \
| > + SIGNAL_ENTRY(WINCH), \
| > + SIGNAL_ENTRY(CHLD), \
| > + SIGNAL_ENTRY(URG), \
| > + SIGNAL_ENTRY(TTIN), \
| > + SIGNAL_ENTRY(TTOU), \
| > + SIGNAL_ENTRY(STOP), \
| > + SIGNAL_ENTRY(CONT), \
| > + SIGNAL_ENTRY(ABRT), \
| > + SIGNAL_ENTRY(FPE), \
| > + SIGNAL_ENTRY(ILL), \
| > + SIGNAL_ENTRY(QUIT), \
| > + SIGNAL_ENTRY(SEGV), \
| > + SIGNAL_ENTRY(TRAP), \
| > + SIGNAL_ENTRY(SYS), \
| > + SIGNAL_ENTRY(BUS), \
| > + SIGNAL_ENTRY(XCPU), \
| > + SIGNAL_ENTRY(XFSZ), \
| > + { -1, "LAST" }, \
| > +}
| > +
| > +#define CKPT_COND_PIDZERO 0x1
| > +#define CKPT_COND_MNTPROC 0x2
| > +#define CKPT_COND_MNTPTY 0x4
| > +
| > +#define CKPT_COND_NONE 0
| > +#define CKPT_COND_ANY ULONG_MAX
| > +
| > +/* default for skip/warn/fail */
| > +#define CKPT_COND_WARN (CKPT_COND_MNTPROC | \
| > + CKPT_COND_MNTPTY)
| > +#define CKPT_COND_FAIL (CKPT_COND_NONE)
| > +
| > diff --git a/restart.c b/restart.c
| > index b37bf81..f65eafb 100644
| > --- a/restart.c
| > +++ b/restart.c
| > @@ -40,6 +40,7 @@
| > #include "eclone.h"
| > #include "genstack.h"
| > #include "compat.h"
| > +#include "common.h"
| >
| > static char usage_str[] =
| > "usage: restart [opts]\n"
| > @@ -102,103 +103,6 @@ static char usage_str[] =
| > * of the checkpoint image stream.
| > */
| >
| > -#define BUFSIZE (4 * 4096)
| > -
| > -static inline void ckpt_msg(int fd, char *format, ...)
| > -{
| > - va_list ap;
| > - char *bufp;
| > - if (fd < 0)
| > - return;
| > -
| > - va_start(ap, format);
| > -
| > - bufp = malloc(BUFSIZE);
| > - if(bufp) {
| > - vsnprintf(bufp, BUFSIZE, format, ap);
| > - write(fd, bufp, strlen(bufp));
| > - }
| > - free(bufp);
| > -
| > - va_end(ap);
| > -}
| > -
| > -#define ckpt_perror(s) \
| > - do { \
| > - ckpt_msg(global_uerrfd, s); \
| > - ckpt_msg(global_uerrfd, ": %s\n", strerror(errno)); \
| > - } while (0)
| > -
| > -#ifdef CHECKPOINT_DEBUG
| > -#define ckpt_dbg(_format, _args...) \
| > - do { \
| > - if (global_debug) \
| > - ckpt_msg(global_uerrfd, "<%d>" _format, \
| > - _gettid(), ##_args); \
| > - } while (0)
| > -#define ckpt_dbg_cont(_format, _args...) \
| > - do { \
| > - if (global_debug) \
| > - ckpt_msg(global_uerrfd, _format, ##_args); \
| > - } while (0)
| > -#else
| > -#define ckpt_dbg(_format, _args...) \
| > - do { } while (0)
| > -#define ckpt_dbg_cont(_format, _args...) \
| > - do { } while (0)
| > -#endif
| > -
| > -#define ckpt_err(...) \
| > - ckpt_msg(global_uerrfd, __VA_ARGS__)
| > -
| > -#define ckpt_verbose(...) \
| > - do { \
| > - if (global_verbose) \
| > - ckpt_msg(global_ulogfd, __VA_ARGS__); \
| > - } while(0)
| > -
| > -struct signal_array {
| > - int signum;
| > - char *sigstr;
| > -};
| > -
| > -#define SIGNAL_ENTRY(signal) { SIG ## signal, #signal }
| > -
| > -#define INIT_SIGNAL_ARRAY { \
| > - { 0, "NONE" }, \
| > - SIGNAL_ENTRY(ALRM), \
| > - SIGNAL_ENTRY(HUP), \
| > - SIGNAL_ENTRY(INT), \
| > - SIGNAL_ENTRY(KILL), \
| > - SIGNAL_ENTRY(PIPE), \
| > - SIGNAL_ENTRY(POLL), \
| > - SIGNAL_ENTRY(PROF), \
| > - SIGNAL_ENTRY(TERM), \
| > - SIGNAL_ENTRY(USR1), \
| > - SIGNAL_ENTRY(USR2), \
| > - SIGNAL_ENTRY(VTALRM), \
| > - SIGNAL_ENTRY(STKFLT), \
| > - SIGNAL_ENTRY(PWR), \
| > - SIGNAL_ENTRY(WINCH), \
| > - SIGNAL_ENTRY(CHLD), \
| > - SIGNAL_ENTRY(URG), \
| > - SIGNAL_ENTRY(TTIN), \
| > - SIGNAL_ENTRY(TTOU), \
| > - SIGNAL_ENTRY(STOP), \
| > - SIGNAL_ENTRY(CONT), \
| > - SIGNAL_ENTRY(ABRT), \
| > - SIGNAL_ENTRY(FPE), \
| > - SIGNAL_ENTRY(ILL), \
| > - SIGNAL_ENTRY(QUIT), \
| > - SIGNAL_ENTRY(SEGV), \
| > - SIGNAL_ENTRY(TRAP), \
| > - SIGNAL_ENTRY(SYS), \
| > - SIGNAL_ENTRY(BUS), \
| > - SIGNAL_ENTRY(XCPU), \
| > - SIGNAL_ENTRY(XFSZ), \
| > - { -1, "LAST" }, \
| > -}
| > -
| > static struct signal_array signal_array[] = INIT_SIGNAL_ARRAY;
| >
| > static char *sig2str(int sig)
| > @@ -399,18 +303,6 @@ struct app_restart_args {
| > int keep_lsm;
| > };
| >
| > -#define CKPT_COND_PIDZERO 0x1
| > -#define CKPT_COND_MNTPROC 0x2
| > -#define CKPT_COND_MNTPTY 0x4
| > -
| > -#define CKPT_COND_NONE 0
| > -#define CKPT_COND_ANY ULONG_MAX
| > -
| > -/* default for skip/warn/fail */
| > -#define CKPT_COND_WARN (CKPT_COND_MNTPROC | \
| > - CKPT_COND_MNTPTY)
| > -#define CKPT_COND_FAIL (CKPT_COND_NONE)
| > -
| > static void usage(char *str)
| > {
| > ckpt_err("%s", str);
| > --
| > 1.6.0.4
| >
| > _______________________________________________
| > Containers mailing list
| > Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
| > https://lists.linux-foundation.org/mailman/listinfo/containers
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 03/12][user-cr] Add app_restart_args->debug
[not found] ` <20100308193929.GA20030-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
@ 2010-03-08 20:42 ` Sukadev Bhattiprolu
0 siblings, 0 replies; 19+ messages in thread
From: Sukadev Bhattiprolu @ 2010-03-08 20:42 UTC (permalink / raw)
To: Serge E. Hallyn; +Cc: Containers
Serge E. Hallyn [serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org] wrote:
| > @@ -583,7 +584,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
| > args->copy_status = 1;
| > break;
| > case 'd':
| > - global_debug = 1;
| > + global_debug = args->debug = 1;
|
| You don't actually need to also set global_debug here, right?
Well, there is a subtlelty in a follow-on patch. Maybe I should move
this set of global_debug there.
global_debug is (eventually) static in both restart.c and restart-main.c
The ckpt_debug() macro defined in common.h uses the global_debug. While
there are no callers of ckpt_debug() in restart-main.c now, setting it
here may enable us just call ckpt_debug() if necessary.
Sukadev
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH 02/12][user-cr] restart: Add args->send_sigint
[not found] ` <20100305223658.GB15939-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
@ 2010-03-15 3:52 ` Oren Laadan
0 siblings, 0 replies; 19+ messages in thread
From: Oren Laadan @ 2010-03-15 3:52 UTC (permalink / raw)
To: Sukadev Bhattiprolu; +Cc: Containers
Nack - the library should not handle signals for callers.
Instead, there should be an interface through which the caller
can ask the library to destroy the tree that it just created.
Thus it will be the caller who catches the signal and acts on
it.
Oren.
Sukadev Bhattiprolu wrote:
> From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
> Date: Thu, 4 Mar 2010 17:37:39 -0800
> Subject: [PATCH 02/12][user-cr] restart: Add args->send_sigint
>
> restart command supports a command line option, --send-sigint to let
> user specify whether SIGINT signal should be processed/ignored during
> restart. Make this a field in 'struct app_restart_args' so that other
> callers of app_restart() in the future can also control the SIGINT
> behavior.
>
> Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
> ---
> restart.c | 6 +++++-
> 1 files changed, 5 insertions(+), 1 deletions(-)
>
> diff --git a/restart.c b/restart.c
> index 0c74bb6..314390c 100644
> --- a/restart.c
> +++ b/restart.c
> @@ -376,6 +376,7 @@ struct app_restart_args {
> int pids;
> int pidns;
> int inspect;
> + int send_sigint;
> char *root;
> int wait;
> int mntns;
> @@ -497,6 +498,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
> args->klogfd = -1;
> args->warn = CKPT_COND_WARN;
> args->fail = CKPT_COND_FAIL;
> + args->send_sigint = -1;
> no_pidns = 0;
>
> klogfile = NULL;
> @@ -554,7 +556,7 @@ static void parse_args(struct app_restart_args *args, int argc, char *argv[])
> ckpt_err("restart: invalid signal\n");
> exit(1);
> }
> - global_send_sigint = sig;
> + args->send_sigint = sig;
> break;
> case 3: /* --pids */
> args->pids = 1;
> @@ -815,6 +817,8 @@ int app_restart(struct app_restart_args *args)
> memset(&ctx, 0, sizeof(ctx));
> ctx.args = args;
>
> + global_send_sigint = args->send_sigint;
> +
> /* input file descriptor (default: stdin) */
> if (args->infd >= 0) {
> if (dup2(args->infd, STDIN_FILENO) < 0) {
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2010-03-15 3:52 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-05 22:34 [PATCH 0/12][user-cr]: Second set of cleanups Sukadev Bhattiprolu
[not found] ` <20100305223439.GA15300-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-05 22:36 ` [PATCH 01/12][user-cr] restart: Mark globals as static Sukadev Bhattiprolu
2010-03-05 22:36 ` [PATCH 02/12][user-cr] restart: Add args->send_sigint Sukadev Bhattiprolu
[not found] ` <20100305223658.GB15939-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-15 3:52 ` Oren Laadan
2010-03-05 22:37 ` [PATCH 03/12][user-cr] Add app_restart_args->debug Sukadev Bhattiprolu
[not found] ` <20100305223723.GC15939-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-08 19:39 ` Serge E. Hallyn
[not found] ` <20100308193929.GA20030-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-08 20:42 ` Sukadev Bhattiprolu
2010-03-05 22:37 ` [PATCH 04/12][user-cr] Add app_restart_args->verbose Sukadev Bhattiprolu
2010-03-05 22:38 ` [PATCH 05/12][user-cr] Add app_restart_args->ulogfd Sukadev Bhattiprolu
2010-03-05 22:38 ` [PATCH 06/12][user-cr] Add app_restart_args->uerrfd Sukadev Bhattiprolu
2010-03-05 22:38 ` [PATCH 07/12][user-cr] Define INIT_SIGNAL_ARRAY Sukadev Bhattiprolu
2010-03-05 22:39 ` [PATCH 08/12][user-cr] Create common.h Sukadev Bhattiprolu
[not found] ` <20100305223907.GH15939-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-08 19:44 ` Serge E. Hallyn
[not found] ` <20100308194427.GB20030-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-08 20:22 ` Sukadev Bhattiprolu
2010-03-05 22:39 ` [PATCH 09/12][user-cr] Create app-checkpoint.h Sukadev Bhattiprolu
2010-03-05 22:39 ` [PATCH 10/12][user-cr] restart: Move main() to restart-main.c Sukadev Bhattiprolu
2010-03-05 22:40 ` [PATCH 11/12][user-cr] checkpoint: Move main() to checkpoint-main.c Sukadev Bhattiprolu
2010-03-05 22:40 ` [PATCH 12/12][user-cr] Have app_restart() return pid Sukadev Bhattiprolu
2010-03-08 19:49 ` [PATCH 0/12][user-cr]: Second set of cleanups Serge E. Hallyn
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.