From b6f7ee69351860d5c072bfac6d3535ef5bf62986 Mon Sep 17 00:00:00 2001 From: Anil Belur Date: Tue, 15 Mar 2016 22:00:39 +0530 Subject: [PATCH] Fixes bug #1556995 - fuel-agent fails to set process group over SSH The issue is fixed with the following changes (as suggested by a-gordeev): fuel-agent must try to execute`os.setpgrp()` only if the PID != PGID. This piece of code covers all cases: 1) executing over SSH. It can't do os.setpgrp() over SSH as the executed script is already a session leader. It will throw EPERM (Operation not permitted). It's the actual reason of the bug. 2) executing locally over shell. It can do os.setpgrp(), the script is a process group leader, but not a session leader. 3) executing over mcollective. It must perform os.setpgrp() as the script is neither a session leader, nor a process group leader. incorporated review comments by a-gordeev, updated use cases as req by Denis. Closes-Bug: #1556995 Change-Id: I29a20e0fdfd80c6b055fc1ebb1c7007e8f69e5eb Signed-off-by: Anil Shashikumar Belur --- bareon/cmd/agent.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bareon/cmd/agent.py b/bareon/cmd/agent.py index 071c43a..e9aedde 100644 --- a/bareon/cmd/agent.py +++ b/bareon/cmd/agent.py @@ -136,7 +136,10 @@ def handle_exception(exc): def main(actions=None): # NOTE(agordeev): get its own process group by calling setpgrp. # Process group is used to distribute signals to subprocesses. - os.setpgrp() + # The main application is already a process group leader, + # then there's no need to call os.setpgrp + if os.getpid() != os.getpgrp(): + os.setpgrp() signal.signal(signal.SIGTERM, handle_sigterm) CONF(sys.argv[1:], project='bareon', version=version.version_info.release_string())