execute: check whether we are actually on a TTY before doing TIOCSCTTY

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.
This commit is contained in:
Lennart Poettering 2017-10-26 18:47:34 +02:00
parent 046a82c1b2
commit 1fb0682e78
1 changed files with 4 additions and 2 deletions

View 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;
}