From 7985831a65d2aa8155444b54f826cd8754753393 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 28 Aug 2018 19:31:34 -0400 Subject: [PATCH] bin/multiuser: Do not exit with an error if stdin is not open. As the comment says, there are a number of scenarios when this is the case, e.g. non-interactive SSH sessions. Change-Id: I3a10043820039f344b3f036f7861c81f6fb7ef05 Reviewed-on: https://review.haiku-os.org/499 Reviewed-by: waddlesplash --- src/bin/multiuser/multiuser_utils.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bin/multiuser/multiuser_utils.cpp b/src/bin/multiuser/multiuser_utils.cpp index 0d916ff2bc..d8804b193f 100644 --- a/src/bin/multiuser/multiuser_utils.cpp +++ b/src/bin/multiuser/multiuser_utils.cpp @@ -191,8 +191,12 @@ setup_environment(struct passwd* passwd, bool preserveEnvironment, bool chngdir) setenv("USER", passwd->pw_name, true); pid_t pid = getpid(); - if (ioctl(STDIN_FILENO, TIOCSPGRP, &pid) != 0) - return errno; + // If stdin is not open, don't bother trying to TIOCSPGRP. (This is the + // case when there is no PTY, e.g. for a noninteractive SSH session.) + if (fcntl(STDIN_FILENO, F_GETFD) != -1) { + if (ioctl(STDIN_FILENO, TIOCSPGRP, &pid) != 0) + return errno; + } if (passwd->pw_gid && setgid(passwd->pw_gid) != 0) return errno;