Close inherited filedescriptors when forking subprocess.
authorStefan Vogel <sv@exept.de>
Mon, 17 Jun 2002 15:09:32 +0200
changeset 2105 f62f8077568e
parent 2104 327f2f77ec12
child 2106 bf5953944ddf
Close inherited filedescriptors when forking subprocess.
TerminalView.st
--- a/TerminalView.st	Fri May 17 07:04:08 2002 +0200
+++ b/TerminalView.st	Mon Jun 17 15:09:32 2002 +0200
@@ -918,7 +918,7 @@
      tell me, whenever something arrives"
 
     |p slaveFD execFdArray closeFdArray blocked exitStatus 
-     stxToCommandPipe commandToStxPipe cmd shell args env wDir shellAndArgs|
+     stxToCommandPipe commandToStxPipe cmd shell args env shellAndArgs|
 
     shellCommand := aCommand.
     shellDirectory := aDirectory.
@@ -955,10 +955,6 @@
                          with:(commandToStxPipe at:2).
 
         closeFdArray := #(). 
-"/                        Array 
-"/                         with:(stxToCommandPipe at:2)
-"/                         with:(commandToStxPipe at:1).
-
 
         outStream := ExternalStream forReadingFromFileDescriptor:(commandToStxPipe at:1).
         inStream := ExternalStream forWritingToFileDescriptor:(stxToCommandPipe at:2).
@@ -982,7 +978,11 @@
         slaveFD := (p at:2) fileDescriptor.
 
         execFdArray := Array with:slaveFD with:slaveFD with:slaveFD.
-        closeFdArray := #().
+
+        "have to close unused filedescriptors.
+         Otherwise, listening sockets may be inherited by child processes"
+
+        closeFdArray := 3 to:OperatingSystem maxNumberOfOpenFiles-1. "close anything but stdin, stdout, stderr"
         
         aCommand isNil ifTrue:[
             shell := OperatingSystem getEnvironment:'SHELL'.
@@ -1769,5 +1769,5 @@
 !TerminalView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/TerminalView.st,v 1.93 2002-02-11 09:32:06 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/TerminalView.st,v 1.94 2002-06-17 13:09:32 stefan Exp $'
 ! !