From 4cff70866377ebb8d60a8d6dbb64ea47f4abf31d Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Tue, 20 Nov 2012 21:05:17 +0400 Subject: [PATCH] tty: Make sure the controlling terminal is restored by session leader The controling terminal should be sestored by a session leader, thus we need to test if the SID we've found in process tree is a leader. Otherwise we might have pretty interesting situation: the user passed -j on dump, ie telling us to inherit shell jobs and on restore procedure the SID get inherited from the crtools but session leader for this sid doesn't belong to our peocess tree and thus we should not try to restore controlling terminal but inherit it as well. Reported-by: Andrey Vagin Signed-off-by: Cyrill Gorcunov Acked-by: Andrey Vagin Signed-off-by: Pavel Emelyanov --- tty.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tty.c b/tty.c index ba8a6c177..1ecb0e515 100644 --- a/tty.c +++ b/tty.c @@ -733,8 +733,13 @@ static int tty_find_restoring_task(struct tty_info *info) return 0; } + /* + * Find out the task which is session leader + * and it can restore the controlling terminal + * for us. + */ item = find_first_sid(info->tie->sid); - if (item) { + if (item && item->pid.virt == item->sid) { pr_info("Set a control terminal %x to %d\n", info->tfe->id, info->tie->sid); return prepare_ctl_tty(item->pid.virt,