]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
fuse/blackmatch: fix linkage problems with daemonize
authorrobk-tahoe <robk-tahoe@allmydata.com>
Thu, 16 Oct 2008 16:36:37 +0000 (09:36 -0700)
committerrobk-tahoe <robk-tahoe@allmydata.com>
Thu, 16 Oct 2008 16:36:37 +0000 (09:36 -0700)
the daemonize() function imported from twisted was causing problems when
run from a frozen (py2app) build.  I simply copied the daemonize function
into this file, and that fixes the problem.

also removed a couple of lines of debugging spam that slipped through.

contrib/fuse/impl_c/blackmatch.py

index 3f6558243f4a67139476a0d3d302d9b66e4d0ea3..cce9a7791d41451d6601c6b7fcf6e06c2214cc01 100644 (file)
@@ -1347,6 +1347,25 @@ class TRPC(object):
         log('shutdown() closing keepalive %s' % (self.keepalive,))
         self.keepalive.close()
 
+# (cut-n-pasted here due to an ImportError / some py2app linkage issues)
+#from twisted.scripts._twistd_unix import daemonize
+def daemonize():
+    # See http://www.erlenstar.demon.co.uk/unix/faq_toc.html#TOC16
+    if os.fork():   # launch child and...
+        os._exit(0) # kill off parent
+    os.setsid()
+    if os.fork():   # launch child and...
+        os._exit(0) # kill off parent again.
+    os.umask(077)
+    null=os.open('/dev/null', os.O_RDWR)
+    for i in range(3):
+        try:
+            os.dup2(null, i)
+        except OSError, e:
+            if e.errno != errno.EBADF:
+                raise
+    os.close(null)
+
 def main(argv):
     log("main(%s)" % (argv,))
 
@@ -1447,7 +1466,6 @@ def main(argv):
         log('\n'+(24*'_')+'init (server)'+(24*'_')+'\n')
 
         log('daemonizing')
-        from twisted.scripts._twistd_unix import daemonize
         daemonize()
 
         cache_timeout = float(config['cache-timeout'])
@@ -1481,12 +1499,10 @@ def main(argv):
         wait_at_most = 8
         while not os.path.exists(socket_path):
             log('waiting for appearance of %r' % (socket_path,))
-            print 'waiting...'
             time.sleep(1)
             if time.time() - waiting_since > wait_at_most:
                 log('%r did not appear within %ss' % (socket_path, wait_at_most))
                 raise IOError(2, 'no socket %s' % (socket_path,))
-            print 'running...'
         #print 'launched server'
         trpc = TRPC(socket_path)