in reply to Re: linux perl - interrupted system calls not restarted?
in thread linux perl - interrupted system calls not restarted?

I need to use SIG{CHLD} in this case - the parent accepts connections, if there is no child running, it starts a child to service the new connection. If there is an existing child, it tells the new client it can't connect as it is in use from ip:port. The child can exit nonzero - when this happens, the parent needs to exit immediately (not at the next accept().

So the parent needs to detect new connections, and a child exiting. The issue I'm concerned with is more general - If I'm using signals anywhere (eg sleep()), do I need to wrap every system call in a loop to retry it??

Replies are listed 'Best First'.
Re^3: linux perl - interrupted system calls not restarted?
by ikegami (Patriarch) on Oct 22, 2009 at 14:37 UTC

    I need to use SIG{CHLD} in this case

    Then you need to check for EINTR

    use Errno qw( EINTR ); for (;;) { my $client = $server->accept(); if (!$client) { next if $! == EINTR; die("Can't accept: $!\n"); } ... }

    If I'm using signals anywhere (eg sleep()), do I need to wrap every system call in a loop to retry it??

    Well, those that are interruptable, yes. That includes sysread. But sysread should already be in a loop since it's not guaranteed to return as many bytes as you requested.