Explorar o código

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)
Unrud %!s(int64=10) %!d(string=hai) anos
pai
achega
367ca6fcbf
Modificáronse 1 ficheiros con 5 adicións e 1 borrados
  1. 5 1
      radicale/__main__.py

+ 5 - 1
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():