[PATCH] Workaround twisted 8.x pipe-based waker

Iustin Pop iusty at k1024.org
Tue Feb 3 20:11:19 UTC 2009


Twisted 8.x uses a waker objects for inter-thread signalling and the on
POSIX platforms the waker uses pipes for communication, which should not
be closed.

For some reasons, sometime the waker deals with its pipes being closed,
while at other times it doesn't. As such, we workaround it by skipping
the waker file descriptors in the utils.Daemonize function. This is
fragile and will break if Twisted changes internals, but it's a simple
workaround for now.

The patch also adds an assert in Daemonize() so that “standard” file
descriptors (0, 1, 2) are not marked to be kept open.
---
 daemons/ganeti-noded |    9 ++++++++-
 lib/utils.py         |    1 +
 2 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded
index 58c3804..892db24 100755
--- a/daemons/ganeti-noded
+++ b/daemons/ganeti-noded
@@ -618,8 +618,15 @@ def main():
       sys.exit(5)
 
   # become a daemon
+  noclose_fds = []
+  if hasattr(reactor, 'waker'):
+    # twisted with waker object which has extra fds in use
+    for attr in ('i', 'o'):
+      val = getattr(reactor.waker, attr, None)
+      if isinstance(val, int):
+        noclose_fds.append(val)
   if options.fork:
-    utils.Daemonize(logfile=constants.LOG_NODESERVER)
+    utils.Daemonize(logfile=constants.LOG_NODESERVER, noclose_fds=noclose_fds)
 
   logger.SetupLogging(twisted_workaround=True, debug=options.debug,
                       program="ganeti-noded")
diff --git a/lib/utils.py b/lib/utils.py
index 083fd2d..f6c00ee 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -1160,6 +1160,7 @@ def Daemonize(logfile, noclose_fds=None):
   # Iterate through and close all file descriptors.
   for fd in range(0, maxfd):
     if noclose_fds and fd in noclose_fds:
+      assert fd > 2, "Cannot keep open standard fd %d" % fd
       continue
     try:
       os.close(fd)
-- 
1.5.6.5


--oyUTqETQ0mS9luUI--





More information about the Pkg-ganeti-devel mailing list