Ignore EPERM for setpgid

In case we are a session leader, we get a harmless EPERM, yet we used
to quit. Stop doing that.

Fixes #6499.
This commit is contained in:
Fabian Homborg 2020-01-13 18:56:23 +01:00
parent 759d5a1fb3
commit 31e6ae0099

View File

@ -1774,9 +1774,14 @@ static void reader_interactive_init(parser_t &parser) {
if (shell_pgid == 0 || session_interactivity() == session_interactivity_t::explicit_) {
shell_pgid = getpid();
if (setpgid(shell_pgid, shell_pgid) < 0) {
FLOG(error, _(L"Failed to assign shell to its own process group"));
wperror(L"setpgid");
exit_without_destructors(1);
// If we're session leader setpgid returns EPERM. The other cases where we'd get EPERM don't apply as we passed our own pid.
//
// This should be harmless, so we ignore it.
if (errno != EPERM) {
FLOG(error, _(L"Failed to assign shell to its own process group"));
wperror(L"setpgid");
exit_without_destructors(1);
}
}
// Take control of the terminal