From 835a4fc42089d12b41bf1564844d7b518cc5e324 Mon Sep 17 00:00:00 2001 From: Brett Randall Date: Thu, 27 Jan 2022 16:03:13 +1100 Subject: [PATCH 1/5] Ensure fd 0 stdin --- gunicorn/util.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gunicorn/util.py b/gunicorn/util.py index a821e357..af414093 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -486,7 +486,10 @@ def daemonize(enable_stdio_inheritance=False): closerange(0, 3) fd_null = os.open(REDIRECT_TO, os.O_RDWR) + # PEP 446, make fd for /dev/null inheritable + os.set_inheritable(fd_null, True) + # expect fd_null to be always 0 here, but in-case not ... if fd_null != 0: os.dup2(fd_null, 0) @@ -494,13 +497,17 @@ def daemonize(enable_stdio_inheritance=False): os.dup2(fd_null, 2) else: - fd_null = os.open(REDIRECT_TO, os.O_RDWR) - # Always redirect stdin to /dev/null as we would # never expect to need to read interactive input. + os.close(0) + + fd_null = os.open(REDIRECT_TO, os.O_RDWR) + # PEP 446, make fd for /dev/null inheritable + os.set_inheritable(fd_null, True) + + # expect fd_null to be always 0 here, but in-case not ... if fd_null != 0: - os.close(0) os.dup2(fd_null, 0) # If stdout and stderr are still connected to From eedc3a38b66b4c5a5ae975baefdc9894288294e4 Mon Sep 17 00:00:00 2001 From: Brett Randall Date: Sun, 30 Jan 2022 17:58:52 +1100 Subject: [PATCH 2/5] Refactoring: common stdin Date: Mon, 31 Jan 2022 07:18:45 +1100 Subject: [PATCH 3/5] Revert "Refactoring: common stdin Date: Mon, 31 Jan 2022 07:26:26 +1100 Subject: [PATCH 4/5] Undo changes that make -R branch logic behave the same as non -R branch, that is, to close(0) and open /dev/null as fd=0 instead of fd=3. (Partially) Revert "Ensure fd 0 stdin Date: Mon, 7 Feb 2022 07:39:34 +1100 Subject: [PATCH 5/5] Updated THANKS. --- THANKS | 1 + 1 file changed, 1 insertion(+) diff --git a/THANKS b/THANKS index 2b226f35..cc48fa5d 100644 --- a/THANKS +++ b/THANKS @@ -109,6 +109,7 @@ Kyle Mulka Lars Hansson Leonardo Santagada Levi Gross +licunlong Ɓukasz Kucharski Mahmoud Hashemi Malthe Borch