From 31e6ae0099ce2bc6082b3f844011352980cee33f Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 13 Jan 2020 18:56:23 +0100 Subject: [PATCH] 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. --- src/reader.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/reader.cpp b/src/reader.cpp index eb406f35e..f5c09082a 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -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