diff options
author | David Dorfman <d3dave@users.noreply.github.com> | 2019-12-28 20:22:09 +0100 |
---|---|---|
committer | Alexander Naumov <alexander_naumov@opensuse.org> | 2019-12-28 20:24:59 +0100 |
commit | 4dd664149c166409b4bd20ada3144a1968f6f355 (patch) | |
tree | 85c0773acd89c6cfd4fc914aae98f41cb1949592 | |
parent | 11a1fc82fb34e18832938d63c3a4471908dae017 (diff) | |
download | screen-4dd664149c166409b4bd20ada3144a1968f6f355.tar.gz |
Disable exclusive mode on TTY device when closing
When opening a TTY we enable exclusive mode to prevent other tools
messing with our connection. When we are done using the TTY the
exclusive mode must be disabled so the TTY can be reconnected to
later. We remember to do this when a break is sent to the device,
but not on window close.
This change ensures we disable exclusive mode on the TTY device
whenever the window is closed.
bug #52248
-rw-r--r-- | src/tty.c | 8 | ||||
-rw-r--r-- | src/tty.h | 1 | ||||
-rw-r--r-- | src/window.c | 14 |
3 files changed, 20 insertions, 3 deletions
@@ -157,6 +157,14 @@ int OpenTTY(char *line, char *opt) return f; } +int CloseTTY(int fd) +{ +#if defined(TIOCEXCL) && defined(TIOCNXCL) + (void)ioctl(fd, TIOCNXCL, NULL); +#endif + return close(fd); +} + /* * Tty mode handling */ @@ -4,6 +4,7 @@ #include "screen.h" int OpenTTY (char *, char *); +int CloseTTY (int); void InitTTY (struct mode *, int); void GetTTY (int, struct mode *); void SetTTY (int, struct mode *); diff --git a/src/window.c b/src/window.c index 213e090..6499595 100644 --- a/src/window.c +++ b/src/window.c @@ -798,15 +798,23 @@ int RemakeWindow(Window *window) void CloseDevice(Window *window) { - if (window->w_ptyfd < 0) + if (window->w_ptyfd < 0) { return; - if (window->w_type == W_TYPE_PTY) { + } + switch (window->w_type) { + case W_TYPE_PTY: /* pty 4 SALE */ (void)chmod(window->w_tty, 0666); (void)chown(window->w_tty, 0, 0); ClosePTY(window->w_ptyfd); - } else + break; + case W_TYPE_PLAIN: + CloseTTY(window->w_ptyfd); + break; + default: close(window->w_ptyfd); + break; + } window->w_ptyfd = -1; window->w_tty[0] = 0; evdeq(&window->w_readev); |