From 51c2e81ba89fddd18f571eb1c27be313a778db38 Mon Sep 17 00:00:00 2001 From: Janky Ferenc Nandor Date: Mon, 10 Oct 2022 19:14:05 +0200 Subject: [PATCH] Fix #1081: no need to call os.setsid() on session leader when attaching If os.setsid() raises exception then the debugger client won't be able to attach to the remote process --- src/debugpy/adapter/__main__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/debugpy/adapter/__main__.py b/src/debugpy/adapter/__main__.py index 54d80cb40..e18ecd560 100644 --- a/src/debugpy/adapter/__main__.py +++ b/src/debugpy/adapter/__main__.py @@ -30,7 +30,10 @@ def main(args): # On POSIX, we need to leave the process group and its session, and then # daemonize properly by double-forking (first fork already happened when # this process was spawned). - os.setsid() + # NOTE: if process is already the session leader, then + # setsid would fail with `operation not permitted` + if os.getsid(os.getpid()) != os.getpid(): + os.setsid() if os.fork() != 0: sys.exit(0)