On Mon, Aug 19, 2002 at 01:43:52AM -0300, Cristiano Lincoln Mattos wrote: > > This works OK in linux, but under Cygwin, the the connection > filehandle/socket and the filehandles that are used to execute the > external program are somehow linked... the connection is only > terminated after the program ends. In the test case below, the > program to be executed is just "/bin/ls; sleep 10; /bin/ls". > Under cygwin, the socket stays alive until all the execution is > finished. Under linux, everything works OK, with the connection > being close, and the execution happenning independently. > Am i doing something wrong with the handles, or is this a > cygwin bug ? Any help appreciated.
We discussed this on EFnet's #poe channel for a while, but nothing came of it. One of the solutions we tried was to close file descriptors 3 and up in the child process. That may not be enough. I just received a similar problem report and suggested a solution that might also work for you. Namely, sockets should have their close-on-exec flags set to true so they don't "bleed" into child processes. If this sample code works for you, I'd like to consider setting the close-on-exec for sockets in SocketFactory. Please let me know. -- Rocco Caputo / [EMAIL PROTECTED] / poe.perl.org / poe.sf.net Forwarded message: | On Sat, Aug 31, 2002 at 05:25:10PM -0400, Steven Chau wrote: | > | > I'm trying to write a server which accepts incoming request. The | > request can be as simple as testing whether a process exists or starting | > up a server related process using POE::Wheel:Run to fork it off. The | > problem I'm having is that the forked child process will inherit all | > parent file descriptors resulting in lingering socket (SocketFactory) | > file handles upon close of Wheel::Run. Is there way I can gracefully | > remove all inherited file descriptors before launching Wheel::Run? | | Good morning! This is an interesting problem. Which operating system | and Perl version are you using? | | It is possible to set the close-on-exec flag for file descriptors | other than 0, 1, or 2. That will cause them to be closed when the | program is executed in the child process. | | I'm leery of touching the close-on-exec flag for file descriptors | since the framework doesn't know what you intend to do with them. | | Here's some untested sample code: | | use POSIX qw(fcntl_h); | use Symbol qw(gensym); | for my $fd (3..255) { | my $handle = gensym; | if (open $handle, "<&=$fd") { | my $flag = fcntl($handle, F_GETFD, 0); | if (defined $flag) { | $flag = 1; | fcntl($handle, F_SETFD, $flag); | } | } | } | | I have a feeling that I can safely do this to sockets created with | SocketFactory. I'll run it past POE's mailing list to be sure. | | -- Rocco Caputo / [EMAIL PROTECTED] / poe.perl.org / poe.sf.net