Replace standard file descriptors of daemon

Overwriting ```sys.stdout``` and ```sys.stderr``` is not sufficient.
(e.g. the logger still uses the old file descriptors)
This commit is contained in:
Unrud 2015-12-22 07:03:51 +01:00 committed by Unrud
parent ecb8ad747e
commit 367ca6fcbf

View File

@ -118,7 +118,11 @@ def run():
os.umask(0)
os.chdir("/")
os.setsid()
sys.stdout = sys.stderr = open(os.devnull, "w")
with open(os.devnull, "r") as null_in:
os.dup2(null_in.fileno(), sys.stdin.fileno())
with open(os.devnull, "w") as null_out:
os.dup2(null_out.fileno(), sys.stdout.fileno())
os.dup2(null_out.fileno(), sys.stderr.fileno())
# Register exit function
def cleanup():