diff --git a/src/add-ons/kernel/drivers/tty/driver.cpp b/src/add-ons/kernel/drivers/tty/driver.cpp index 8344ecf2d4..9fb643b679 100644 --- a/src/add-ons/kernel/drivers/tty/driver.cpp +++ b/src/add-ons/kernel/drivers/tty/driver.cpp @@ -27,8 +27,9 @@ static const int kMaxCachedSemaphores = 8; int32 api_version = B_CUR_DRIVER_API_VERSION; -static char *sDeviceNames[kNumTTYs * 2 + 1]; - // reserve space for "pt/" and "tt/" entries and the terminating NULL +static char *sDeviceNames[kNumTTYs * 2 + 2]; + // reserve space for "pt/" and "tt/" entries, "tty", and the terminating + // NULL struct mutex gGlobalTTYLock; struct mutex gTTYCookieLock; @@ -100,6 +101,8 @@ init_driver(void) } } + sDeviceNames[2 * kNumTTYs] = "tty"; + tty_add_debugger_commands(); return B_OK; diff --git a/src/add-ons/kernel/drivers/tty/slave.cpp b/src/add-ons/kernel/drivers/tty/slave.cpp index e1cddb292d..5cc3f42e8a 100644 --- a/src/add-ons/kernel/drivers/tty/slave.cpp +++ b/src/add-ons/kernel/drivers/tty/slave.cpp @@ -31,9 +31,18 @@ struct tty gSlaveTTYs[kNumTTYs]; static status_t slave_open(const char *name, uint32 flags, void **_cookie) { + // Get the tty index: Opening "/dev/tty" means opening the process' + // controlling tty. int32 index = get_tty_index(name); - if (index >= (int32)kNumTTYs) - return B_ERROR; + if (strcmp(name, "tty") == 0) { + index = team_get_controlling_tty(); + if (index < 0) + return B_NOT_ALLOWED; + } else { + index = get_tty_index(name); + if (index >= (int32)kNumTTYs) + return B_ERROR; + } TRACE(("slave_open: TTY index = %ld (name = %s)\n", index, name));