From e654cf38800228c363d47a507139bcca5bf31d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 13 May 2020 13:04:52 +0200 Subject: [PATCH] slave: configure pts to be the controlling terminal of the forked process --- CHANGELOG.md | 1 + slave.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e763f6dd..8c7e0c00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ * `OSC 12 ?` to return the cursor color, not the cursor's text color. * `OSC 12;#000000` to configure the cursor to use inverted foreground/background colors. +* Call `ioctl(TIOCSCTTY)` on the pts fd in the slave process. ### Security diff --git a/slave.c b/slave.c index edd8e2cb..57bedc75 100644 --- a/slave.c +++ b/slave.c @@ -10,6 +10,7 @@ #include #include +#include #include #define LOG_MODULE "slave" @@ -93,6 +94,12 @@ slave_exec(int ptmx, char *argv[], int err_fd, bool login_shell) goto err; } + if (ioctl(pts, TIOCSCTTY, 0) < 0) { + LOG_ERRNO("failed to configure controlling terminal"); + goto err; + } + + if (dup2(pts, STDIN_FILENO) == -1 || dup2(pts, STDOUT_FILENO) == -1 || dup2(pts, STDERR_FILENO) == -1)