All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: Oren Laadan <orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Subject: Re: [PATCH] user-cr: add --input-fd to take input from a specific fd
Date: Mon, 26 Oct 2009 11:25:06 -0500	[thread overview]
Message-ID: <20091026162506.GD23564@us.ibm.com> (raw)
In-Reply-To: <1256508791-2394-1-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>

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

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

> ---
>  restart.c |   34 +++++++++++++++++++++++++++-------
>  1 files changed, 27 insertions(+), 7 deletions(-)
> 
> diff --git a/restart.c b/restart.c
> index 14d8aec..ca8e062 100644
> --- a/restart.c
> +++ b/restart.c
> @@ -72,7 +72,8 @@ static char usage_str[] =
>  "     --copy-status      imitate exit status of root task (implies -w)\n"
>  "  -W,--no-wait          do not wait for root task to terminate\n"
>  "  -F,--freezer=CGROUP   freeze tasks in freezer group CGROUP on success\n"
> -"  -i,--input=FILE      read data from FILE instead of standard input\n"
> +"  -i,--input=FILE       read data from FILE instead of standard input\n"
> +"     --input-fd=FD      read data from file descriptor FD (instead of stdin)\n"
>  "     --inspect          inspect image on-the-fly for error records\n"
>  "  -v,--verbose          verbose output\n"
>  "  -d,--debug            debugging output\n"
> @@ -353,6 +354,7 @@ struct args {
>  	int copy_status;
>  	char *freezer;
>  	char *input;
> +	int inputfd;
>  };
> 
>  static void usage(char *str)
> @@ -384,6 +386,7 @@ static void parse_args(struct args *args, int argc, char *argv[])
>  		{ "signal",	required_argument,	NULL, 4 },
>  		{ "inspect",	no_argument,		NULL, 5 },
>  		{ "input",	required_argument,	NULL, 'i' },
> +		{ "input-fd",	required_argument,	NULL, 7 },
>  		{ "root",	required_argument,	NULL, 'r' },
>  		{ "wait",	no_argument,		NULL, 'w' },
>  		{ "show-status",	no_argument,	NULL, 1 },
> @@ -401,6 +404,7 @@ static void parse_args(struct args *args, int argc, char *argv[])
>  	/* defaults */
>  	memset(args, 0, sizeof(*args));
>  	args->wait = 1;
> +	args->inputfd = -1;
> 
>  	while (1) {
>  		int c = getopt_long(argc, argv, optc, opts, NULL);
> @@ -420,6 +424,13 @@ static void parse_args(struct args *args, int argc, char *argv[])
>  		case 'i':
>  			args->input = optarg;
>  			break;
> +		case 7:
> +			args->inputfd = str2num(optarg);
> +			if (args->inputfd < 0) {
> +				printf("restart: invalid file descriptor\n");
> +				exit(1);
> +			}
> +			break;
>  		case 'p':
>  			args->pidns = 1;
>  			break;
> @@ -507,6 +518,11 @@ static void parse_args(struct args *args, int argc, char *argv[])
>  		printf("Invalid mix of --self with multiprocess options\n");
>  		exit(1);
>  	}
> +
> +	if (args->input && args->inputfd >= 0) {
> +		printf("Invalid used of both -i/--input and --input-fd\n");
> +		exit(1);
> +	}
>  }
> 
>  static void report_exit_status(int status, char *str, int debug)
> @@ -652,19 +668,23 @@ int main(int argc, char *argv[])
>  	parse_args(&args, argc, argv);
>  	ctx.args = &args;
> 
> -	/* input file (default: stdin) */
> +	/* input file ? */
>  	if (args.input) {
> -		ret = open(args.input, O_RDONLY, 0);
> -		if (ret < 0) {
> +		args.inputfd = open(args.input, O_RDONLY, 0);
> +		if (args.inputfd < 0) {
>  			perror("open input file");
>  			exit(1);
>  		}
> -		if (dup2(ret, STDIN_FILENO) < 0) {
> +	}
> +
> +	/* input file descriptor (default: stdin) */
> +	if (args.inputfd >= 0) {
> +		if (dup2(args.inputfd, STDIN_FILENO) < 0) {
>  			perror("dup2 input file");
>  			exit(1);
>  		}
> -		if (ret != STDIN_FILENO)
> -			close(ret);
> +		if (args.inputfd != STDIN_FILENO)
> +			close(args.inputfd);
>  	}
> 
>  	/* freezer preparation */
> -- 
> 1.6.0.4
> 
> _______________________________________________
> Containers mailing list
> Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
> https://lists.linux-foundation.org/mailman/listinfo/containers

  parent reply	other threads:[~2009-10-26 16:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-25 22:13 [PATCH] user-cr: add --input-fd to take input from a specific fd Oren Laadan
     [not found] ` <1256508791-2394-1-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-10-26 16:25   ` Serge E. Hallyn [this message]
2009-10-26 17:29   ` Matt Helsley

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=20091026162506.GD23564@us.ibm.com \
    --to=serue-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=orenl-RdfvBDnrOixBDgjK7y7TUQ@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.