nearly-tickless-tinc

Loïc Grenié loic.grenie at gmail.com
Mon May 30 08:39:48 CEST 2011


2011/5/29 Guus Sliepen <guus at tinc-vpn.org>:
> On Sun, May 29, 2011 at 10:17:03PM +0200, Loïc Grenié wrote:
>
>> > but to prevent race conditions, only pselect() should change the
>> > signal mask in the main loop.
>>
>>      I might be wrong but I think there is no race condition in my code.
>>   However I can eliminate all the problems if you tell me that tincd
>>   does not block/unblock SIGHUP and SIGALARM while running
>>   (block_mask can be initialized before the main loop, signals blocked
>>   there and never unblocked). In that case the main loop is mostly
>>   unchanged (except for computing "next_event") and we can
>>   emulate pselect() when it does not exist (or is racy) by a
>>   standard select() with a 1s timeout (without blocking signals
>>   obviously).
>
> Tinc never changes the signal mask. The only thing it does is install signal
> handlers. So you can read the signal mask once before main_loop(), add SIGUP
> and SIGALARM, and use that for pselect().

     Perfect.

>>      The "selfpipe" trick is another option obviously if you prefer. It is
>>   not very elegant but has no real downside (I don't know whether
>>   there are pipes under Windows, but since there are no signals
>>   anyway...).
>
> Windows has pipes. But again, I think it is less work and code to use
> pselect(). You might want to check whether it is properly supported on the BSD
> variants (including MacOS/X) though.

    My wife has a Mac with MacOS/X (I think). I should be able to compile
  something next week. pselect seems to be available since at least 10.3

http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/pselect.3.html

    However, once again, if pselect() is not available or not compatible or
  whatever it can be emulated with a select:

int
tinc_pselect(int nfds, fd_set *readfds, fd_set *writefds,
                   fd_set *exceptfds, const struct timespec *timeout,
                   const sigset_t *sigmask)
{
    struct timeval tv;
    tv.tv_sec = 1;
    tv.tv_usec = 0;
    return select(nfds, readfds, writefds, exceptfds, &tv);
}

       Loïc

PS: in my first patch, the signal mask I gave as last argument of
  pselect() was wrong, sorry. The attached patch should be correct.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tinc.diff
Type: text/x-patch
Size: 2924 bytes
Desc: not available
URL: <http://www.tinc-vpn.org/pipermail/tinc-devel/attachments/20110530/1fe13f22/attachment-0001.bin>


More information about the tinc-devel mailing list