[Devel] [PATCH 09/13][user-cr]: checkpoint: Remove args->output

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


From: Sukadev Bhattiprolu <sukadev at linux.vnet.ibm.com>
Date: Wed, 3 Mar 2010 10:49:19 -0800
Subject: [PATCH 09/13][user-cr]: checkpoint: Remove args->output

'struct args' has both an 'outfd' and an 'output' field. The ->output
field is only needed to parse arguments and by moving the open of
the output file into parse_args(), we can drop the ->output field
and just use ->outfd.

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

diff --git a/checkpoint.c b/checkpoint.c
index 464e359..df405cb 100644
--- a/checkpoint.c
+++ b/checkpoint.c
@@ -40,7 +40,6 @@ static char usage_str[] =
 "";
 
 struct args {
-	char *output;
 	int outfd;
 	char *logfile;
 	int logfd;
@@ -84,10 +83,12 @@ static void parse_args(struct args *args, int argc, char *argv[])
 		{ NULL,		0,			NULL, 0 }
 	};
 	static char optc[] = "hvco:l:";
+	char *output;
 
 	/* defaults */
 	args->outfd = -1;
 	args->logfd = -1;
+	output = NULL;
 
 	while (1) {
 		int c = getopt_long(argc, argv, optc, opts, NULL);
@@ -99,7 +100,7 @@ static void parse_args(struct args *args, int argc, char *argv[])
 		case 'h':
 			usage(usage_str);
 		case 'o':
-			args->output = optarg;
+			output = optarg;
 			break;
 		case 1:
 			args->outfd = str2num(optarg);
@@ -129,10 +130,20 @@ static void parse_args(struct args *args, int argc, char *argv[])
 		}
 	}
 
-	if (args->output && args->outfd >= 0) {
-		printf("Invalid used of both -o/--output and --output-fd\n");
+	if (output && args->outfd >= 0) {
+		printf("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) {
+			perror("open output file");
+			exit(1);
+		}
+	}
+
 	if (args->logfile && args->logfd >= 0) {
 		printf("Invalid used of both -l/--logfile and --logfile-fd\n");
 		exit(1);
@@ -162,16 +173,6 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
-	/* output file */
-	if (args.output) {
-		args.outfd = open(args.output,
-				     O_RDWR | O_CREAT | O_EXCL, 0644);
-		if (args.outfd < 0) {
-			perror("open output file");
-			exit(1);
-		}
-	}
-
 	/* output file descriptor (default: stdout) */
 	if (args.outfd < 0)
 		args.outfd = STDOUT_FILENO;
-- 
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