Commit 9c579cfd authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

sfd_type: Add SELF_STDIN_OFF service fd and call helpers where needed

We will need it for slave ttys migration. They serve for one purpose --
to clone self stdio descriptor and use it with tty layer, which will
be addressed in further patches.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent b0b7ed11
......@@ -88,6 +88,9 @@ static int crtools_prepare_shared(void)
if (collect_inet_sockets())
return -1;
if (tty_prep_fds())
return -1;
return 0;
}
......
......@@ -535,7 +535,7 @@ int prepare_fds(struct pstree_item *me)
ret = close_old_fds(me);
if (ret)
return ret;
goto err;
pr_info("Opening fdinfo-s\n");
......@@ -562,6 +562,8 @@ int prepare_fds(struct pstree_item *me)
break;
}
err:
tty_fini_fds();
return ret;
}
......
......@@ -116,6 +116,7 @@ enum sfd_type {
SELF_EXE_FD_OFF,
PROC_FD_OFF,
CTL_TTY_OFF,
SELF_STDIN_OFF,
SERVICE_FD_MAX
};
......
......@@ -20,4 +20,7 @@ extern int 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__ */
......@@ -84,6 +84,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.
......@@ -1022,3 +1023,26 @@ int dump_tty(struct fd_parms *p, int lfd, const struct cr_fdset *set)
{
return do_dump_gen_file(p, lfd, &tty_ops, set);
}
int tty_prep_fds(void)
{
self_stdin = get_service_fd(SELF_STDIN_OFF);
if (!isatty(STDIN_FILENO)) {
pr_err("Standart stream is not a terminal, aborting\n");
return -1;
}
if (dup2(STDIN_FILENO, self_stdin) < 0) {
self_stdin = -1;
pr_perror("Can't dup stdin to SELF_STDIN_OFF");
return -1;
}
return 0;
}
void tty_fini_fds(void)
{
close_safe(&self_stdin);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment