Close pty to avoid leak

This commit is contained in:
Bob Lantz
2018-08-23 11:43:43 -07:00
parent 092863f113
commit 6e887d0788
+11 -7
View File
@@ -145,12 +145,12 @@ class Node( object ):
# Spawn a shell subprocess in a pseudo-tty, to disable buffering # Spawn a shell subprocess in a pseudo-tty, to disable buffering
# in the subprocess and insulate it from signals (e.g. SIGINT) # in the subprocess and insulate it from signals (e.g. SIGINT)
# received by the parent # received by the parent
master, slave = pty.openpty() self.master, self.slave = pty.openpty()
self.shell = self._popen( cmd, stdin=slave, stdout=slave, stderr=slave, self.shell = self._popen( cmd, stdin=self.slave, stdout=self.slave,
close_fds=False ) stderr=self.slave, close_fds=False )
# XXX BL: This doesn't seem right, and we should also probably # XXX BL: This doesn't seem right, and we should also probably
# close our files when we exit... # close our files when we exit...
self.stdin = os.fdopen( master, 'r' ) self.stdin = os.fdopen( self.master, 'r' )
self.stdout = self.stdin self.stdout = self.stdin
self.pid = self.shell.pid self.pid = self.shell.pid
self.pollOut = select.poll() self.pollOut = select.poll()
@@ -217,9 +217,13 @@ class Node( object ):
# for intfName in self.intfNames(): # for intfName in self.intfNames():
# if self.name in intfName: # if self.name in intfName:
# quietRun( 'ip link del ' + intfName ) # quietRun( 'ip link del ' + intfName )
if self.waitExited and self.shell: if self.shell:
debug( 'waiting for', self.pid, 'to terminate\n' ) # Close ptys
self.shell.wait() self.stdin.close()
os.close(self.slave)
if self.waitExited:
debug( 'waiting for', self.pid, 'to terminate\n' )
self.shell.wait()
self.shell = None self.shell = None
# Subshell I/O, commands and control # Subshell I/O, commands and control