From 719f971dea542ed5566217eaba96fab111de154c Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 24 Apr 2008 21:16:57 +0000 Subject: [PATCH] Controlling terminal related changes: * It is possible to acquire a tty that is already open, iff it is not a controlling terminal yet and the process is a session leader. * Also set the terminal process group when acquiring a controlling terminal. telnetd/login and sshd are a lot happier now (and so am I :-)). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25132 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/drivers/tty/slave.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/add-ons/kernel/drivers/tty/slave.cpp b/src/add-ons/kernel/drivers/tty/slave.cpp index 5cc3f42e8a..8dfd3328c9 100644 --- a/src/add-ons/kernel/drivers/tty/slave.cpp +++ b/src/add-ons/kernel/drivers/tty/slave.cpp @@ -70,8 +70,16 @@ slave_open(const char *name, uint32 flags, void **_cookie) // If already open, we allow only processes from the same session // to open the tty again. pid_t ttySession = gSlaveTTYs[index].settings->session_id; - if (ttySession < 0 || ttySession != sessionID) - return B_NOT_ALLOWED; + if (ttySession >= 0) { + if (ttySession != sessionID) + return B_NOT_ALLOWED; + makeControllingTTY = false; + } else { + // The tty is not associated with a session yet. The process needs + // to be a session leader. + if (makeControllingTTY && processID != sessionID) + return B_NOT_ALLOWED; + } } slave_cookie *cookie = (slave_cookie *)malloc(sizeof(struct slave_cookie)); @@ -95,12 +103,14 @@ slave_open(const char *name, uint32 flags, void **_cookie) if (gSlaveTTYs[index].open_count == 0) { gSlaveTTYs[index].lock = gMasterTTYs[index].lock; + gSlaveTTYs[index].settings->session_id = -1; + gSlaveTTYs[index].settings->pgrp_id = -1; + } - if (makeControllingTTY) { - gSlaveTTYs[index].settings->session_id = sessionID; - team_set_controlling_tty(gSlaveTTYs[index].index); - } else - gSlaveTTYs[index].settings->session_id = -1; + if (makeControllingTTY) { + gSlaveTTYs[index].settings->session_id = sessionID; + gSlaveTTYs[index].settings->pgrp_id = sessionID; + team_set_controlling_tty(gSlaveTTYs[index].index); } add_tty_cookie(cookie);