[CRIU] Re: [PATCH 3/5] tty: Add tty_prep_fds, tty_fini_fds helpers
Cyrill Gorcunov
gorcunov at openvz.org
Fri Sep 28 09:40:28 EDT 2012
On Fri, Sep 28, 2012 at 05:35:15PM +0400, Andrew Vagin wrote:
> On Thu, Sep 27, 2012 at 04:17:40PM +0400, Cyrill Gorcunov wrote:
> > They will serve for one purpose -- to clone
> > self stdio descriptor and use it with tty
> > migration if needed.
> >
> > Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> > ---
> > include/tty.h | 3 +++
> > tty.c | 32 ++++++++++++++++++++++++++++++++
> > 2 files changed, 35 insertions(+), 0 deletions(-)
> >
> > diff --git a/include/tty.h b/include/tty.h
> > index eccc3f2..cb860b1 100644
> > --- a/include/tty.h
> > +++ b/include/tty.h
> > @@ -20,4 +20,7 @@ extern void tty_setup_slavery(void);
> >
> > extern int tty_verify_active_pairs(void);
> >
> > +extern int tty_prep_fds(void);
> > +extern void tty_fini_fds(void);
> > +
> > #endif /* CR_TTY_H__ */
> > diff --git a/tty.c b/tty.c
> > index ee63273..acb89bc 100644
> > --- a/tty.c
> > +++ b/tty.c
> > @@ -80,6 +80,7 @@ struct tty_info {
> >
> > static LIST_HEAD(all_tty_info_entries);
> > static LIST_HEAD(all_ttys);
> > +static int self_stdin = -1;
> >
> > /*
> > * Usually an application has not that many ttys opened.
> > @@ -1055,3 +1056,34 @@ int dump_tty(struct fd_parms *p, int lfd, const struct cr_fdset *set)
> > {
> > return do_dump_gen_file(p, lfd, &tty_ops, set);
> > }
> > +
> > +/*
> > + * FIXME
> > + *
> > + * Strictly speaking we don't need to prepare self stdin clone
> > + * for each process, but the concept is that only one migrating tty
> > + * is allowed so this helpers should be called once only in context
> > + * of a process which owns migrating tty fd.
>
> You can call it from crtools_prepare_shared
yup, i'll update
> > + */
> > +int tty_prep_fds(void)
> > +{
> > + self_stdin = get_service_fd(SELF_STDIN_OFF);
> > +
> > + if (!isatty(fileno(stdin))) {
> > + pr_err("Standart stream is not a terminal, aborting\n");
> > + return -1;
> > + }
> > +
> > + if (dup2(fileno(stdin), self_stdin) < 0) {
>
> fileno(stdin) = STDIN_FILENO
yeah, thanks!
Cyrill
More information about the CRIU
mailing list