Commit 3c54e236 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

tty: Require @stdin being tty to inherit from in a laze fashion

When migrating process it might not have slave tty peers at
all so instead of exiting early just wait for its real usage
and only then fail.
Reported-by: 's avatarManuel Rodríguez Pascual <manuel.rodriguez.pascual@gmail.com>
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
parent d43fff4d
...@@ -119,6 +119,7 @@ struct tty_dump_info { ...@@ -119,6 +119,7 @@ struct tty_dump_info {
size_t tty_data_size; size_t tty_data_size;
}; };
static bool stdin_isatty = false;
static LIST_HEAD(all_tty_info_entries); static LIST_HEAD(all_tty_info_entries);
static LIST_HEAD(all_ttys); static LIST_HEAD(all_ttys);
...@@ -931,11 +932,17 @@ static int pty_open_unpaired_slave(struct file_desc *d, struct tty_info *slave) ...@@ -931,11 +932,17 @@ static int pty_open_unpaired_slave(struct file_desc *d, struct tty_info *slave)
*/ */
if (likely(slave->inherit)) { if (likely(slave->inherit)) {
if (!stdin_isatty) {
pr_err("Don't have tty to inherit session from, aborting\n");
return -1;
}
fd = dup(get_service_fd(SELF_STDIN_OFF)); fd = dup(get_service_fd(SELF_STDIN_OFF));
if (fd < 0) { if (fd < 0) {
pr_perror("Can't dup SELF_STDIN_OFF"); pr_perror("Can't dup SELF_STDIN_OFF");
return -1; return -1;
} }
pr_info("Migrated slave peer %x -> to fd %d\n", pr_info("Migrated slave peer %x -> to fd %d\n",
slave->tfe->id, fd); slave->tfe->id, fd);
} else { } else {
...@@ -2041,10 +2048,10 @@ int tty_prep_fds(void) ...@@ -2041,10 +2048,10 @@ int tty_prep_fds(void)
if (!opts.shell_job) if (!opts.shell_job)
return 0; return 0;
if (!isatty(STDIN_FILENO)) { if (!isatty(STDIN_FILENO))
pr_err("Standard stream is not a terminal, aborting\n"); pr_info("Standard stream is not a terminal, may fail later\n");
return -1; else
} stdin_isatty = true;
if (install_service_fd(SELF_STDIN_OFF, STDIN_FILENO) < 0) { if (install_service_fd(SELF_STDIN_OFF, STDIN_FILENO) < 0) {
pr_perror("Can't dup stdin to SELF_STDIN_OFF"); pr_perror("Can't dup stdin to SELF_STDIN_OFF");
......
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