Signals interrupt accept() - bug in perldoc perlipc?

  • Thread starter Peter Valdemar Morch
  • Start date
P

Peter Valdemar Morch

I've discovered that at least CHLD signals in 5.8.0+ terminate
accept(Client,Server) calls, so accept() now returns undef if CHLD is
recieved if a %SIG signal handler has been assigned. Also, posts in
this group have suggested to test for $! == EINTR, but on my Debian
Testing 5.8.3, $! == ECHILD, not EINTR. (Is this significant?)

In 5.6.0 on Linux, the accept() call blocked until a server connected,
regardless of signals. I expect that this change is related to "Safe
Signals" in 5.8, but I didn't quite expect this behavior from the
vague "Note that breaking out from potentially blocking operations
should still work, though" in perldoc perl58delta. At least the
behavior of accept() has changed...

Have any other signal related behaviors changed in a similar fashion?
(So I can proactively inspect and fix bugs rather than find them
through testing ;-)

Unless I have misunderstood something, I suggest that the loop in the
Socket Server example in perldoc perlipc:

for ( ; $paddr = accept(Client,Server); close Client) {
... e.g. start and terminate sub-process ...
}

is changed to:

while (1) {
my $paddr = accept($clientHandle,Server);
# Here $! == ECHILD, and not == EINTR as suggested in accept(2)
# when a child finishes, so don't test $! in case you add
# other signal handling later
if ($paddr) {
... e.g. start and terminate sub-process ...
}
}

(I had to change a similar loop in my own code)

Because otherwise, if a subprocess ends during the accept() call,
causing \&REAPER to be called, accept will return false and end the
for loop, that really was intended to run indefinitely.

Perhaps a mention of this interrupted accept() behaviour is also
warranted in perldoc -f accept and in perldoc perl58delta.

Some working examples that demonstrate the behavior can be found here:
http://demo.capmon.dk/~pvm/clientServer-5.8/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top