mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Refactoring: common stdin </dev/null.
This commit is contained in:
parent
835a4fc420
commit
eedc3a38b6
@ -472,6 +472,19 @@ def daemonize(enable_stdio_inheritance=False):
|
|||||||
|
|
||||||
os.umask(0o22)
|
os.umask(0o22)
|
||||||
|
|
||||||
|
# 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.dup2(fd_null, 0)
|
||||||
|
|
||||||
# In both the following any file descriptors above stdin
|
# In both the following any file descriptors above stdin
|
||||||
# stdout and stderr are left untouched. The inheritance
|
# stdout and stderr are left untouched. The inheritance
|
||||||
# option simply allows one to have output go to a file
|
# option simply allows one to have output go to a file
|
||||||
@ -479,37 +492,17 @@ def daemonize(enable_stdio_inheritance=False):
|
|||||||
# to use --error-log option.
|
# to use --error-log option.
|
||||||
|
|
||||||
if not enable_stdio_inheritance:
|
if not enable_stdio_inheritance:
|
||||||
# Remap all of stdin, stdout and stderr on to
|
# Remap remaining fds stdout and stderr on to
|
||||||
# /dev/null. The expectation is that users have
|
# /dev/null. The expectation is that users have
|
||||||
# specified the --error-log option.
|
# specified the --error-log option.
|
||||||
|
|
||||||
closerange(0, 3)
|
# 1/stdout, 2/stderr - 0/stdin already done above
|
||||||
|
closerange(1, 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)
|
|
||||||
|
|
||||||
os.dup2(fd_null, 1)
|
os.dup2(fd_null, 1)
|
||||||
os.dup2(fd_null, 2)
|
os.dup2(fd_null, 2)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# 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.dup2(fd_null, 0)
|
|
||||||
|
|
||||||
# If stdout and stderr are still connected to
|
# If stdout and stderr are still connected to
|
||||||
# their original file descriptors we check to see
|
# their original file descriptors we check to see
|
||||||
# if they are associated with terminal devices.
|
# if they are associated with terminal devices.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user