changeset 372:dae8eb26eaa3

dup2 to devnull
author Matt Johnston <matt@ucc.asn.au>
date Tue, 26 Jun 2012 21:46:08 +0800
parents 7dec59b7eeef
children f0a61b700d23
files server/ts.py server/utils.py
diffstat 2 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/server/ts.py	Tue Jun 26 21:36:54 2012 +0800
+++ b/server/ts.py	Tue Jun 26 21:46:08 2012 +0800
@@ -25,6 +25,7 @@
 import config
 
 from utils import monotonic_time, retry, readline, crc16
+import utils
 
 lightblue = None
 try:
--- a/server/utils.py	Tue Jun 26 21:36:54 2012 +0800
+++ b/server/utils.py	Tue Jun 26 21:46:08 2012 +0800
@@ -99,6 +99,13 @@
     return crc
 
 def cheap_daemon():
+    print "Daemonising."
+    sys.stdout.flush()
+    sys.stderr.flush()
+    out = file('/dev/null', 'a+')
+    os.dup2(out.fileno(), sys.stdout.fileno())
+    os.dup2(out.fileno(), sys.stderr.fileno())
+
     try:
         pid = os.fork()
         if pid > 0: