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 <waddlesplash@gmail.com>
This commit is contained in:
Augustin Cavalier 2018-08-28 19:31:34 -04:00 committed by waddlesplash
parent d28caaed68
commit 7985831a65

View File

@ -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;