Linux Container Development
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Subject: Re: [user-cr][PATCH 2/2] Add --mount-pty option to mount new devpts
Date: Mon, 15 Feb 2010 08:33:16 -0600	[thread overview]
Message-ID: <20100215143316.GC28038@us.ibm.com> (raw)
In-Reply-To: <1266224833-10902-2-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>

Quoting Oren Laadan (orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org):
> Based on Serge Hallyn's patch:
> 
>   "Trivial patch, and I'm not sure whether we want this or want to do
>   it this way.  But it saves me having to do it during my restart.sh
>   wrapper shell-script."
> 
> Make sure that the old /dev/pts is un-mounted prior to the mount of
> the new one.
> 
> Signed-off-by: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>

Thanks, Oren.  For both patches:

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

(regardless of which way you decide to go with the /proc umount error
handling)

thanks,
-serge

> ---
>  restart.c |   40 ++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 40 insertions(+), 0 deletions(-)
> 
> diff --git a/restart.c b/restart.c
> index f42b456..e3c4a5c 100644
> --- a/restart.c
> +++ b/restart.c
> @@ -53,6 +53,7 @@ static char usage_str[] =
>  "     --signal=SIG       send SIG to root task on SIGINT (default: SIGKILL\n"
>  "                        to container root, SIGINT otherwise)\n"
>  "     --mntns            restart under a private mounts namespace\n"
> +"     --mount-pty        start in a new devpts namespace to supprt ptys\n"
>  "  -w,--wait             wait for root task to termiate (default)\n"
>  "     --show-status      show exit status of root task (implies -w)\n"
>  "     --copy-status      imitate exit status of root task (implies -w)\n"
> @@ -275,6 +276,7 @@ int global_send_sigint = -1;
>  int global_sent_sigint;
> 
>  static int ckpt_remount_proc(void);
> +static int ckpt_remount_devpts(void);
> 
>  static int ckpt_build_tree(struct ckpt_ctx *ctx);
>  static int ckpt_init_tree(struct ckpt_ctx *ctx);
> @@ -342,6 +344,7 @@ struct args {
>  	char *root;
>  	int wait;
>  	int mntns;
> +	int mnt_pty;
>  	int show_status;
>  	int copy_status;
>  	char *freezer;
> @@ -432,6 +435,7 @@ static void parse_args(struct args *args, int argc, char *argv[])
>  		{ "debug",	no_argument,		NULL, 'd' },
>  		{ "warn-pidzero",	no_argument,	NULL, 9 },
>  		{ "fail-pidzero",	no_argument,	NULL, 10 },
> +		{ "mount-pty",	no_argument,		NULL, 12 },
>  		{ NULL,		0,			NULL, 0 }
>  	};
>  	static char optc[] = "hdvkpPwWF:r:i:l:";
> @@ -538,6 +542,9 @@ static void parse_args(struct args *args, int argc, char *argv[])
>  		case 11:
>  			args->mntns = 1;
>  			break;
> +		case 12:
> +			args->mnt_pty = 1;
> +			break;
>  		default:
>  			usage(usage_str);
>  		}
> @@ -591,6 +598,9 @@ static void parse_args(struct args *args, int argc, char *argv[])
>  		printf("Invalid used of both -l/--logfile and --logfile-fd\n");
>  		exit(1);
>  	}
> +
> +	if (args->mnt_pty)
> +		args->mntns = 1;
>  }
> 
>  static void report_exit_status(int status, char *str, int debug)
> @@ -785,6 +795,10 @@ int main(int argc, char *argv[])
>  		exit(1);
>  	}
> 
> +	/* remount /dev/pts ? */
> +	if (args.mnt_pty && ckpt_remount_devpts() < 0)
> +		exit(1);
> +
>  	/* self-restart ends here: */
>  	if (args.self) {
>  		restart(getpid(), STDIN_FILENO, RESTART_TASKSELF, args.logfd);
> @@ -916,6 +930,32 @@ static int ckpt_collect_child(struct ckpt_ctx *ctx)
>  	return ckpt_parse_status(status, mimic, verbose);
>  }
> 
> +static int ckpt_remount_devpts(void)
> +{
> +	struct stat ptystat;
> +
> +	/* make sure /dev/ptmx is a link else we'll just break */
> +	if (lstat("/dev/ptmx", &ptystat) < 0) {
> +		perror("stat /dev/ptmx");
> +		return -1;
> +	}
> +	if ((ptystat.st_mode & S_IFMT) != S_IFLNK) {
> +		ckpt_err("Error: /dev/ptmx must be a link to /dev/pts/ptmx\n");
> +		return -1;
> +	}
> +
> +	if (umount2("/dev/pts", MNT_DETACH) < 0) {
> +		perror("umount -l /dev/pts");
> +		return -1;
> +	}
> +	if (mount("pts", "/dev/pts", "devpts", 0, "newinstance") < 0) {
> +		perror("mount -t devpts -o newinstance");
> +		return -1;
> +	}
> +
> +	return 0;
> +}
> +
>  static int ckpt_close_files(void)
>  {
>  	char fdpath[64], *endp;
> -- 
> 1.6.3.3

  parent reply	other threads:[~2010-02-15 14:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-15  9:07 [user-cr][PATCH 1/2] restart: remount /proc for new tasks created with CLONE_NEWPID Oren Laadan
     [not found] ` <1266224833-10902-1-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2010-02-15  9:07   ` [user-cr][PATCH 2/2] Add --mount-pty option to mount new devpts Oren Laadan
     [not found]     ` <1266224833-10902-2-git-send-email-orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2010-02-15 14:33       ` Serge E. Hallyn [this message]
2010-02-15 20:50       ` Serge E. Hallyn
     [not found]         ` <20100215205003.GA16950-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-02-16  9:55           ` Oren Laadan
2010-02-15 14:31   ` [user-cr][PATCH 1/2] restart: remount /proc for new tasks created with CLONE_NEWPID Serge E. Hallyn

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=20100215143316.GC28038@us.ibm.com \
    --to=serue-r/jw6+rmf7hqt0dzr+alfa@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox