All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] user-cr: add --output-fd to write output to a specific fd
@ 2009-10-25 22:13 Oren Laadan
       [not found] ` <1256508801-2426-1-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Oren Laadan @ 2009-10-25 22:13 UTC (permalink / raw)
  To: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA

This is useful if the user would like redirect the output to
e.g, a socket or any other already open file descriptor when
invoking 'checkpoint'.

Also useful if the user would like to append an existing file.

Signed-off-by: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
---
 checkpoint.c |   47 +++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/checkpoint.c b/checkpoint.c
index c116daf..aef954b 100644
--- a/checkpoint.c
+++ b/checkpoint.c
@@ -32,12 +32,14 @@ static char usage_str[] =
 "\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"
 "  -c,--container        require the PID is a container-init\n"
 "  -v,--verbose          verbose output\n"
 "";
 
 struct args {
 	char *output;
+	int outputfd;
 	int container;
 	int verbose;
 };
@@ -53,17 +55,33 @@ static void usage(char *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 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 },
 		{ "container",	no_argument,		NULL, 'c' },
 		{ "verbose",	no_argument,		NULL, 'v' },
 		{ NULL,		0,			NULL, 0 }
 	};
 	static char optc[] = "hvco:";
 
+	/* defaults */
+	args->outputfd = -1;
+
 	while (1) {
 		int c = getopt_long(argc, argv, optc, opts, NULL);
 		if (c == -1)
@@ -76,6 +94,13 @@ static void parse_args(struct args *args, int argc, char *argv[])
 		case 'o':
 			args->output = optarg;
 			break;
+		case 1:
+			args->outputfd = str2num(optarg);
+			if (args->outputfd < 0) {
+				printf("checkpoint: invalid file descriptor\n");
+				exit(1);
+			}
+			break;
 		case 'c':
 			args->container = 1;
 			break;
@@ -86,6 +111,12 @@ static void parse_args(struct args *args, int argc, char *argv[])
 			usage(usage_str);
 		}
 	}
+
+	if (args->output && args->outputfd >= 0) {
+		printf("Invalid used of both -o/--output and --output-fd\n");
+		exit(1);
+	}
+	
 }
 
 int main(int argc, char *argv[])
@@ -111,19 +142,23 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
-	/* output file (default: stdout) */
+	/* output file */
 	if (args.output) {
-		ret = open(args.output, O_RDWR | O_CREAT, 0);
-		if (ret < 0) {
+		args.outputfd = open(args.output, O_RDWR | O_CREAT, 0);
+		if (args.outputfd < 0) {
 			perror("open output file");
 			exit(1);
 		}
-		if (dup2(ret, STDOUT_FILENO) < 0) {
+	}
+
+	/* output file descriptor (default: stdout) */
+	if (args.outputfd >= 0) {
+		if (dup2(args.outputfd, STDOUT_FILENO) < 0) {
 			perror("dup2 output file");
 			exit(1);
 		}
-		if (ret != STDOUT_FILENO)
-			close(ret);
+		if (args.outputfd != STDOUT_FILENO)
+			close(args.outputfd);
 	}
 
 	ret = checkpoint(pid, STDOUT_FILENO, flags);
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] user-cr: add --output-fd to write output to a specific fd
       [not found] ` <1256508801-2426-1-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
@ 2009-10-26 16:50   ` Serge E. Hallyn
  2009-10-26 17:43   ` Matt Helsley
  1 sibling, 0 replies; 4+ messages in thread
From: Serge E. Hallyn @ 2009-10-26 16:50 UTC (permalink / raw)
  To: Oren Laadan; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA

Quoting Oren Laadan (orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org):
> This is useful if the user would like redirect the output to
> e.g, a socket or any other already open file descriptor when
> invoking 'checkpoint'.
> 
> Also useful if the user would like to append an existing file.
> 
> Signed-off-by: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>

Acked-by: Serge Hallyn <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

> ---
>  checkpoint.c |   47 +++++++++++++++++++++++++++++++++++++++++------
>  1 files changed, 41 insertions(+), 6 deletions(-)
> 
> diff --git a/checkpoint.c b/checkpoint.c
> index c116daf..aef954b 100644
> --- a/checkpoint.c
> +++ b/checkpoint.c
> @@ -32,12 +32,14 @@ static char usage_str[] =
>  "\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"
>  "  -c,--container        require the PID is a container-init\n"
>  "  -v,--verbose          verbose output\n"
>  "";
> 
>  struct args {
>  	char *output;
> +	int outputfd;
>  	int container;
>  	int verbose;
>  };
> @@ -53,17 +55,33 @@ static void usage(char *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 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 },
>  		{ "container",	no_argument,		NULL, 'c' },
>  		{ "verbose",	no_argument,		NULL, 'v' },
>  		{ NULL,		0,			NULL, 0 }
>  	};
>  	static char optc[] = "hvco:";
> 
> +	/* defaults */
> +	args->outputfd = -1;
> +
>  	while (1) {
>  		int c = getopt_long(argc, argv, optc, opts, NULL);
>  		if (c == -1)
> @@ -76,6 +94,13 @@ static void parse_args(struct args *args, int argc, char *argv[])
>  		case 'o':
>  			args->output = optarg;
>  			break;
> +		case 1:
> +			args->outputfd = str2num(optarg);
> +			if (args->outputfd < 0) {
> +				printf("checkpoint: invalid file descriptor\n");
> +				exit(1);
> +			}
> +			break;
>  		case 'c':
>  			args->container = 1;
>  			break;
> @@ -86,6 +111,12 @@ static void parse_args(struct args *args, int argc, char *argv[])
>  			usage(usage_str);
>  		}
>  	}
> +
> +	if (args->output && args->outputfd >= 0) {
> +		printf("Invalid used of both -o/--output and --output-fd\n");
> +		exit(1);
> +	}
> +	
>  }
> 
>  int main(int argc, char *argv[])
> @@ -111,19 +142,23 @@ int main(int argc, char *argv[])
>  		exit(1);
>  	}
> 
> -	/* output file (default: stdout) */
> +	/* output file */
>  	if (args.output) {
> -		ret = open(args.output, O_RDWR | O_CREAT, 0);
> -		if (ret < 0) {
> +		args.outputfd = open(args.output, O_RDWR | O_CREAT, 0);
> +		if (args.outputfd < 0) {
>  			perror("open output file");
>  			exit(1);
>  		}
> -		if (dup2(ret, STDOUT_FILENO) < 0) {
> +	}
> +
> +	/* output file descriptor (default: stdout) */
> +	if (args.outputfd >= 0) {
> +		if (dup2(args.outputfd, STDOUT_FILENO) < 0) {
>  			perror("dup2 output file");
>  			exit(1);
>  		}
> -		if (ret != STDOUT_FILENO)
> -			close(ret);
> +		if (args.outputfd != STDOUT_FILENO)
> +			close(args.outputfd);
>  	}
> 
>  	ret = checkpoint(pid, STDOUT_FILENO, flags);
> -- 
> 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] 4+ messages in thread

* Re: [PATCH] user-cr: add --output-fd to write output to a specific fd
       [not found] ` <1256508801-2426-1-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
  2009-10-26 16:50   ` Serge E. Hallyn
@ 2009-10-26 17:43   ` Matt Helsley
       [not found]     ` <20091026174305.GI31446-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
  1 sibling, 1 reply; 4+ messages in thread
From: Matt Helsley @ 2009-10-26 17:43 UTC (permalink / raw)
  To: Oren Laadan; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA

On Sun, Oct 25, 2009 at 06:13:21PM -0400, Oren Laadan wrote:
> This is useful if the user would like redirect the output to
> e.g, a socket or any other already open file descriptor when
> invoking 'checkpoint'.
> 
> Also useful if the user would like to append an existing file.
> 
> Signed-off-by: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
> ---
>  checkpoint.c |   47 +++++++++++++++++++++++++++++++++++++++++------
>  1 files changed, 41 insertions(+), 6 deletions(-)
> 
> diff --git a/checkpoint.c b/checkpoint.c
> index c116daf..aef954b 100644
> --- a/checkpoint.c
> +++ b/checkpoint.c
> @@ -32,12 +32,14 @@ static char usage_str[] =
>  "\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"
>  "  -c,--container        require the PID is a container-init\n"
>  "  -v,--verbose          verbose output\n"
>  "";
> 
>  struct args {
>  	char *output;
> +	int outputfd;
>  	int container;
>  	int verbose;
>  };
> @@ -53,17 +55,33 @@ static void usage(char *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;
> +}

It'd be nice to see common functions in a shared .o  between
checkpoint and restart. 

Cheers,
	-Matt Helsley

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] user-cr: add --output-fd to write output to a specific fd
       [not found]     ` <20091026174305.GI31446-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
@ 2009-10-26 19:39       ` Oren Laadan
  0 siblings, 0 replies; 4+ messages in thread
From: Oren Laadan @ 2009-10-26 19:39 UTC (permalink / raw)
  To: Matt Helsley; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA


yeah .. I was lazy .. will add another patch.

Oren.

Matt Helsley wrote:
> On Sun, Oct 25, 2009 at 06:13:21PM -0400, Oren Laadan wrote:
>> This is useful if the user would like redirect the output to
>> e.g, a socket or any other already open file descriptor when
>> invoking 'checkpoint'.
>>
>> Also useful if the user would like to append an existing file.
>>
>> Signed-off-by: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
>> ---
>>  checkpoint.c |   47 +++++++++++++++++++++++++++++++++++++++++------
>>  1 files changed, 41 insertions(+), 6 deletions(-)
>>
>> diff --git a/checkpoint.c b/checkpoint.c
>> index c116daf..aef954b 100644
>> --- a/checkpoint.c
>> +++ b/checkpoint.c
>> @@ -32,12 +32,14 @@ static char usage_str[] =
>>  "\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"
>>  "  -c,--container        require the PID is a container-init\n"
>>  "  -v,--verbose          verbose output\n"
>>  "";
>>
>>  struct args {
>>  	char *output;
>> +	int outputfd;
>>  	int container;
>>  	int verbose;
>>  };
>> @@ -53,17 +55,33 @@ static void usage(char *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;
>> +}
> 
> It'd be nice to see common functions in a shared .o  between
> checkpoint and restart. 
> 
> Cheers,
> 	-Matt Helsley
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-10-26 19:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-25 22:13 [PATCH] user-cr: add --output-fd to write output to a specific fd Oren Laadan
     [not found] ` <1256508801-2426-1-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-10-26 16:50   ` Serge E. Hallyn
2009-10-26 17:43   ` Matt Helsley
     [not found]     ` <20091026174305.GI31446-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2009-10-26 19:39       ` Oren Laadan

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.