From 367ca6fcbf19507da8ba4a40713eb9d86a90d529 Mon Sep 17 00:00:00 2001 From: Unrud Date: Tue, 22 Dec 2015 07:03:51 +0100 Subject: [PATCH] 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) --- radicale/__main__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/radicale/__main__.py b/radicale/__main__.py index 6e47ee8..547abe1 100644 --- a/radicale/__main__.py +++ b/radicale/__main__.py @@ -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():