Signals interrupt accept() - bug in perldoc perlipc?

Discussion in 'Perl Misc' started by Peter Valdemar Morch, Jun 22, 2004.

  1. 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:
    Peter Valdemar Morch, Jun 22, 2004
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Nagle
    Dennis Lee Bieber
    Jan 16, 2008
  2. Shea Martin
    Shea Martin
    Mar 22, 2006
  3. Jaap Karssenberg

    conflict between man perlipc and man perlfunc !?

    Jaap Karssenberg, Jan 9, 2004, in forum: Perl Misc
    Jaap Karssenberg
    Jan 9, 2004
  4. Nitzan Shaked

    perlipc doc / another race (?)

    Nitzan Shaked, Jun 27, 2005, in forum: Perl Misc
  5. all mail refused

    perlipc bidirectional unix domain socket

    all mail refused, Sep 22, 2007, in forum: Perl Misc
    all mail refused
    Sep 23, 2007

Share This Page