From 46efd10d4a4e956b9c4e803de1f78a9b39eecac8 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 54d80cb4..e18ecd56 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)