All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
Cc: Containers
	<containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
Subject: [PATCH 09/14][user-cr] checkpoint: Move main() to checkpoint-main.c
Date: Thu, 18 Mar 2010 23:33:39 -0700	[thread overview]
Message-ID: <20100319063339.GI24844@us.ibm.com> (raw)
In-Reply-To: <20100319062659.GA23838-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 09/14][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 7e1d701..6c9ff93 100644
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,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))
@@ -56,6 +56,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

  parent reply	other threads:[~2010-03-19  6:33 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-19  6:26 [PATCH 0/14][user-cr] Enable linking with LIBLXC Sukadev Bhattiprolu
     [not found] ` <20100319062659.GA23838-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-19  6:31   ` [PATCH 01/14][user-cr] Add app_restart_args->debug Sukadev Bhattiprolu
2010-03-19  6:31   ` [PATCH 02/14][user-cr] Add app_restart_args->verbose Sukadev Bhattiprolu
2010-03-19  6:32   ` [PATCH 03/14][user-cr] Add app_restart_args->ulogfd Sukadev Bhattiprolu
2010-03-19  6:32   ` [PATCH 04/14][user-cr] Add app_restart_args->uerrfd Sukadev Bhattiprolu
2010-03-19  6:32   ` [PATCH 05/14][user-cr] Define INIT_SIGNAL_ARRAY Sukadev Bhattiprolu
2010-03-19  6:32   ` [PATCH 06/14][user-cr] Create common.h Sukadev Bhattiprolu
2010-03-19  6:33   ` [PATCH 07/14][user-cr] Create app-checkpoint.h Sukadev Bhattiprolu
2010-03-19  6:33   ` [PATCH 08/14][user-cr] restart: Move main() to restart-main.c Sukadev Bhattiprolu
2010-03-19  6:33   ` Sukadev Bhattiprolu [this message]
2010-03-19  6:33   ` [PATCH 10/14][user-cr] Have app_restart() return pid Sukadev Bhattiprolu
2010-03-19  6:34   ` [PATCH 11/14][user-cr] restart: Define process_args() Sukadev Bhattiprolu
2010-03-19  6:34   ` [PATCH 12/14][user-cr] app_restart(): mnt-pty implies mntns Sukadev Bhattiprolu
2010-03-19  6:34   ` [PATCH 13/14][user-cr] restart: Move args checking to app_restart() Sukadev Bhattiprolu
2010-03-19  6:34   ` [PATCH 14/14][user-cr] Minimize unshare() calls Sukadev Bhattiprolu
     [not found]     ` <20100319063448.GN24844-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-24  4:08       ` Serge E. Hallyn
2010-03-24  4:26       ` Serge E. Hallyn
2010-03-30  7:04   ` [PATCH 0/14][user-cr] Enable linking with LIBLXC Oren Laadan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100319063339.GI24844@us.ibm.com \
    --to=sukadev-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.