]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
execute: check whether we are actually on a TTY before doing TIOCSCTTY
authorLennart Poettering <lennart@poettering.net>
Thu, 26 Oct 2017 16:47:34 +0000 (18:47 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 17 Nov 2017 10:13:44 +0000 (11:13 +0100)
Given that Linux assigns the same ioctl numbers ot multiple subsystems,
we should be careful when invoking ioctls, so that we don't end up
calling something we wouldn't want to call.

src/core/execute.c

index 8083cccab25809f6d063fd974ec9adf6da4275ee..547ab40657aa930ea582cebdb0b9f525e1363586 100644 (file)
@@ -425,8 +425,10 @@ static int setup_input(
                         return -errno;
 
                 /* Try to make this the controlling tty, if it is a tty, and reset it */
-                (void) ioctl(STDIN_FILENO, TIOCSCTTY, context->std_input == EXEC_INPUT_TTY_FORCE);
-                (void) reset_terminal_fd(STDIN_FILENO, true);
+                if (isatty(STDIN_FILENO)) {
+                        (void) ioctl(STDIN_FILENO, TIOCSCTTY, context->std_input == EXEC_INPUT_TTY_FORCE);
+                        (void) reset_terminal_fd(STDIN_FILENO, true);
+                }
 
                 return STDIN_FILENO;
         }