On Tue, Jul 15, 2003 at 03:38:58PM +0200, Michael Kleis wrote: > i have a question regarding the switch from perl 5.6 to perl 5.8 and the > usage of fork and signal handlers. > > I have written a script (on a debian linux (sid) box, perl 5.6.1) > that is using fork and a signal handler (if a CHLD signal received some > cleanup function is called). > After updating to perl 5.8 this script is not longer working as before. > > After the switch: > > client connects to server (i.e. my perl script) > server forks > forked process is handling the client request > client closes connection (forked process exits --> signal handler > performs cleanup) > server is terminating ! > > I have read that there was a change of the perl fork implementation > from 5.6 to 5.8. > Could someone give me a hint how to fix the problem ?
I'd imagine that your accept() isn't being restarted. How does it work if you change the loop to look like this? use Errno; while (1) { my $client = $server->accept or do { next if $!{EINTR}; last; }; spawn(\&function, "whatever"); } I don't think fork() has changed, but the signal dispatch mechanism is new in 5.8: Safe Signals Perl used to be fragile in that signals arriving at inopportune moments could corrupt Perl's internal state. Now Perl postpones handling of signals until it's safe (between opcodes). This change may have surprising side effects because signals no longer interrupt Perl instantly. Perl will now first finish whatever it was doing, like finishing an internal operation (like sort()) or an external operation (like an I/O operation), and only then look at any arrived signals (and before starting the next operation). No more corrupt internal state since the current operation is always finished first, but the signal may take more time to get heard. Note that breaking out from potentially blocking operations should still work, though. However: I don't think this was supposed to break your script. It also breaks all the server socket examples in perlipc. Anybody think this _isn't_ a bug? -- Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]