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:
    http://demo.capmon.dk/~pvm/clientServer-5.8/
     
    Peter Valdemar Morch, Jun 22, 2004
    #1
    1. Advertising

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
    Replies:
    12
    Views:
    1,623
    Dennis Lee Bieber
    Jan 16, 2008
  2. Shea Martin
    Replies:
    6
    Views:
    211
    Shea Martin
    Mar 22, 2006
  3. Jaap Karssenberg

    conflict between man perlipc and man perlfunc !?

    Jaap Karssenberg, Jan 9, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    176
    Jaap Karssenberg
    Jan 9, 2004
  4. Nitzan Shaked

    perlipc doc / another race (?)

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

    perlipc bidirectional unix domain socket

    all mail refused, Sep 22, 2007, in forum: Perl Misc
    Replies:
    6
    Views:
    505
    all mail refused
    Sep 23, 2007
Loading...

Share This Page