[Devel] [PATCH 12/13][user-cr]: Define app_checkpoint()

Sukadev Bhattiprolu sukadev at linux.vnet.ibm.com
Wed Mar 3 23:50:28 PST 2010


From: Sukadev Bhattiprolu <sukadev at linux.vnet.ibm.com>
Date: Wed, 3 Mar 2010 11:35:47 -0800
Subject: [PATCH 12/13][user-cr]: Define app_checkpoint()

Move the bulk of the code that implements application checkpoint into
a separate function, app_checkpoint() and make a main() a wrapper to
that function. This would help export the core checkpoint functionality
as a library interface in a future patch.

Signed-off-by: Sukadev Bhattiprolu <sukadev at linux.vnet.ibm.com>
---
 checkpoint.c |   50 +++++++++++++++++++++++++++++---------------------
 1 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/checkpoint.c b/checkpoint.c
index d5fcfee..4044da8 100644
--- a/checkpoint.c
+++ b/checkpoint.c
@@ -160,12 +160,36 @@ static void parse_args(struct app_checkpoint_args *args, int argc, char *argv[])
 	}
 }
 
+int app_checkpoint(int pid, unsigned long flags,
+				struct app_checkpoint_args *args)
+{
+	int ret;
+
+	/* output file descriptor (default: stdout) */
+	if (args->outfd < 0)
+		args->outfd = STDOUT_FILENO;
+
+	/* output file descriptor (default: none) */
+	if (args->logfd < 0)
+		args->logfd = CHECKPOINT_FD_NONE;
+
+	ret = checkpoint(pid, args->outfd, flags, args->logfd);
+
+	if (ret < 0) {
+		perror("checkpoint");
+		fprintf(stderr, "(you may use 'ckptinfo -e' for more info)\n"); 
+	} else if (args->verbose) {
+		fprintf(stderr, "checkpoint id %d\n", ret);
+	}
+
+	return (ret > 0 ? 0 : 1);
+}
+
 int main(int argc, char *argv[])
 {
 	struct app_checkpoint_args args;
 	unsigned long flags = 0;
 	pid_t pid;
-	int ret;
 
 	memset(&args, 0, sizeof(args));
 	parse_args(&args, argc, argv);
@@ -174,31 +198,15 @@ int main(int argc, char *argv[])
 	if (argc != 1)
 		usage(usage_str);
 
-	if (!args.container)
-		flags |= CHECKPOINT_SUBTREE;
-
 	pid = atoi(argv[optind]);
 	if (pid <= 0) {
 		printf("invalid pid\n");
 		exit(1);
 	}
 
-	/* output file descriptor (default: stdout) */
-	if (args.outfd < 0)
-		args.outfd = STDOUT_FILENO;
-
-	/* output file descriptor (default: none) */
-	if (args.logfd < 0)
-		args.logfd = CHECKPOINT_FD_NONE;
-
-	ret = checkpoint(pid, args.outfd, flags, args.logfd);
-
-	if (ret < 0) {
-		perror("checkpoint");
-		fprintf(stderr, "(you may use 'ckptinfo -e' for more info)\n"); 
-	} else if (args.verbose) {
-		fprintf(stderr, "checkpoint id %d\n", ret);
-	}
+	if (!args.container)
+		flags |= CHECKPOINT_SUBTREE;
 
-	return (ret > 0 ? 0 : 1);
+	return app_checkpoint(pid, flags, &args);
 }
+
-- 
1.6.0.4

_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers




More information about the Devel mailing list