Fix daemonize problem that surfaced in start_all
authordbs <dbs@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 9 Nov 2010 14:22:25 +0000 (14:22 +0000)
committerdbs <dbs@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 9 Nov 2010 14:22:25 +0000 (14:22 +0000)
Thanks to Michael Giarlo for reporting the problem, Bill Erickson
for pointing the way to the solution, and http://bugs.python.org/issue5313
for providing me with more context for the problem & solution.

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@2061 9efc2488-bf62-4759-914b-345cdb29e865

src/python/osrf/system.py

index 0df4d73..dff93b0 100644 (file)
@@ -101,11 +101,17 @@ class System(object):
     def daemonize(parentExit=True):
         pid = os.fork() 
         if pid == 0:
-            os.chdir('/')
-            os.setsid()
-            sys.stdin.close()
-            sys.stdout.close()
-            sys.stderr.close()
+            try:
+                os.chdir('/')
+                os.setsid()
+                sys.stdin.close()
+                sys.stdin = open(os.devnull)
+                sys.stdout.close()
+                sys.stdout = open(os.devnull)
+                sys.stderr.close()
+                sys.stderr = open(os.devnull)
+            except (OSError, ValueError):
+                pass
         elif parentExit:
             os._exit(0)