From 1f8ec65e97a9d607b8f975d51d4ceae268aad504 Mon Sep 17 00:00:00 2001 From: Bruno Kleinert Date: Fri, 9 Jan 2026 09:00:21 +0100 Subject: [PATCH] Check if stdin is a tty When stdin links to /dev/null, which is the case for systemd service units, select() returns immediately. That causes the loop to endlessly read() 0 bytes and eats up 100% of a processor core. isatty() checks if railcontrol has a "real" stdin available. If that is not the case, do not select() and read() stdin but use the 1s delay as for silent mode. --- RailControl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RailControl.cpp b/RailControl.cpp index e130014d..6cb925a2 100644 --- a/RailControl.cpp +++ b/RailControl.cpp @@ -24,7 +24,7 @@ along with RailControl; see the file LICENCE. If not see #include #include #include -#include //close; +#include //close; isatty #include #include "ArgumentHandler.h" @@ -183,7 +183,7 @@ int main (int argc, char* argv[]) // wait for q or r followed by \n or SIGINT or SIGTERM do { - if (silent) + if (!isatty(STDIN_FILENO) || silent) { Utils::Utils::SleepForSeconds(1); }