Skip to content

Commit e9c4f74

Browse files
committed
Revert "Refactoring: common stdin </dev/null."
This reverts commit a4f2867.
1 parent eedc3a3 commit e9c4f74

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

gunicorn/util.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -472,37 +472,44 @@ def daemonize(enable_stdio_inheritance=False):
472472

473473
os.umask(0o22)
474474

475-
# Always redirect stdin to /dev/null as we would
476-
# never expect to need to read interactive input.
477-
478-
os.close(0)
479-
480-
fd_null = os.open(REDIRECT_TO, os.O_RDWR)
481-
# PEP 446, make fd for /dev/null inheritable
482-
os.set_inheritable(fd_null, True)
483-
484-
# expect fd_null to be always 0 here, but in-case not ...
485-
if fd_null != 0:
486-
os.dup2(fd_null, 0)
487-
488475
# In both the following any file descriptors above stdin
489476
# stdout and stderr are left untouched. The inheritance
490477
# option simply allows one to have output go to a file
491478
# specified by way of shell redirection when not wanting
492479
# to use --error-log option.
493480

494481
if not enable_stdio_inheritance:
495-
# Remap remaining fds stdout and stderr on to
482+
# Remap all of stdin, stdout and stderr on to
496483
# /dev/null. The expectation is that users have
497484
# specified the --error-log option.
498485

499-
# 1/stdout, 2/stderr - 0/stdin already done above
500-
closerange(1, 3)
486+
closerange(0, 3)
487+
488+
fd_null = os.open(REDIRECT_TO, os.O_RDWR)
489+
# PEP 446, make fd for /dev/null inheritable
490+
os.set_inheritable(fd_null, True)
491+
492+
# expect fd_null to be always 0 here, but in-case not ...
493+
if fd_null != 0:
494+
os.dup2(fd_null, 0)
501495

502496
os.dup2(fd_null, 1)
503497
os.dup2(fd_null, 2)
504498

505499
else:
500+
# Always redirect stdin to /dev/null as we would
501+
# never expect to need to read interactive input.
502+
503+
os.close(0)
504+
505+
fd_null = os.open(REDIRECT_TO, os.O_RDWR)
506+
# PEP 446, make fd for /dev/null inheritable
507+
os.set_inheritable(fd_null, True)
508+
509+
# expect fd_null to be always 0 here, but in-case not ...
510+
if fd_null != 0:
511+
os.dup2(fd_null, 0)
512+
506513
# If stdout and stderr are still connected to
507514
# their original file descriptors we check to see
508515
# if they are associated with terminal devices.

0 commit comments

Comments
 (0)