From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
Cc: sukadev-6JnAsaTVvkgX0ybBhKVfKdBPR1lH4CV8@public.gmane.org,
Containers
<containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
Subject: [PATCH 11/12][user-cr] checkpoint: Move main() to checkpoint-main.c
Date: Fri, 5 Mar 2010 14:40:09 -0800 [thread overview]
Message-ID: <20100305224009.GK15939@us.ibm.com> (raw)
In-Reply-To: <20100305223439.GA15300-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
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
next prev parent reply other threads:[~2010-03-05 22:40 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Sukadev Bhattiprolu [this message]
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
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=20100305224009.GK15939@us.ibm.com \
--to=sukadev-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org \
--cc=sukadev-6JnAsaTVvkgX0ybBhKVfKdBPR1lH4CV8@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