]> code.delx.au - offlineimap/commitdiff
Don't leave preauthtunnel zombies with autorefresh
authorJohn Goerzen <jgoerzen@complete.org>
Wed, 14 Mar 2007 01:54:19 +0000 (02:54 +0100)
committerJohn Goerzen <jgoerzen@complete.org>
Wed, 14 Mar 2007 01:54:19 +0000 (02:54 +0100)
From: Peter Colberg

Hello,

using offlineimap with the preauthtunnel option to start a remote
IMAP daemon via ssh, a zombie process is left behind during the
autorefresh sleep period if not holding the connection open.

Above behaviour is a result of using os.popen2 to spawn the tunnel
process, which makes it impossible waiting for the child process
to terminate when shutting down the tunnel.

The patch included below fixes the issue by employing the Popen
class from the subprocess module, which seems to be the preferred
way to spawn processes and connect to their pipes in any case (at
least since python version 2.4.4, which fixes a memory leak in the
subprocess module).

Regards,
Peter

fixes deb#410730

offlineimap/imaplib.py

index a4bdc22d6b81273afb25f036987e72e95758dcb8..d70819e700b66202c6d3a105a7bb114b3b3923c4 100644 (file)
@@ -22,7 +22,7 @@ Public functions:       Internaldate2tuple
 
 __version__ = "2.52"
 
-import binascii, re, socket, time, random, sys, os
+import binascii, re, socket, time, random, subprocess, sys, os
 from offlineimap.ui import UIBase
 
 __all__ = ["IMAP4", "Internaldate2tuple", "Internaldate2epoch",
@@ -1049,7 +1049,9 @@ class IMAP4_Tunnel(IMAP4):
 
     def open(self, host, port):
         """The tunnelcmd comes in on host!"""
-        self.outfd, self.infd = os.popen2(host, "t", 0)
+        self.process = subprocess.Popen(host, shell=True, close_fds=True,
+                        stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+        (self.outfd, self.infd) = (self.process.stdin, self.process.stdout)
 
     def read(self, size):
         retval = ''
@@ -1066,6 +1068,7 @@ class IMAP4_Tunnel(IMAP4):
     def shutdown(self):
         self.infd.close()
         self.outfd.close()
+        self.process.wait()
         
 
 class sslwrapper: