From 1e795d4e16951b68de7c3d55df9be4d3a693cd8f Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 28 May 2021 14:59:43 +0200 Subject: [PATCH] Fix #175: Ensure finit does not acquire 'dev' as controlling TTY When starting a getty Finit checks first that the configured TTY device actually exists and is a TTY. This patch, by Tobias Waldekranz, ensures Finit (PID 1) doesn't acquire the TTY device as a controlling TTY. If that happens PID 1 will get all signals sent to the process actually started with the device as its controlling TTY. Signed-off-by: Tobias Waldekranz Signed-off-by: Joachim Wiberg --- src/helpers.c | 2 +- src/tty.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers.c b/src/helpers.c index 56f3aab1..f5913a2d 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -115,7 +115,7 @@ static void add_console(char *cons) } /* this requires we have /dev mounted && a device there */ - fds[num_cons] = open(path, O_WRONLY); + fds[num_cons] = open(path, O_WRONLY | O_NOCTTY); if (fds[num_cons] < 0) { _pe("Failed opening console %s", path); return; diff --git a/src/tty.c b/src/tty.c index 408b1a1c..1fbb902e 100644 --- a/src/tty.c +++ b/src/tty.c @@ -229,7 +229,7 @@ int tty_exists(char *dev) struct termios c; int fd, rc; - fd = open(dev, O_RDWR); + fd = open(dev, O_RDWR | O_NOCTTY); if (-1 == fd) return 0;