dnsmasq: fix lockup when interfaces disappear
[librecmc/librecmc.git] / package / network / services / dnsmasq / patches / 003-fix-unresponsiveness-on-interface-disappearance.patch
1 From 5782649ad95382dd558df97b33b64e854d8789fb Mon Sep 17 00:00:00 2001
2 From: Simon Kelley <simon@thekelleys.org.uk>
3 Date: Thu, 18 Sep 2014 22:08:58 +0100
4 Subject: [PATCH] Fix bug which caused dnsmasq to become unresponsive when an
5  interface goes.
6
7 ---
8
9 diff --git a/src/util.c b/src/util.c
10 index df751c7..a729f33 100644
11 --- a/src/util.c
12 +++ b/src/util.c
13 @@ -570,18 +570,28 @@ void bump_maxfd(int fd, int *max)
14  
15  int retry_send(void)
16  {
17 -   struct timespec waiter;
18 +  /* Linux kernels can return EAGAIN in perpetuity when calling
19 +     sendmsg() and the relevant interface has gone. Here we loop
20 +     retrying in EAGAIN for 1 second max, to avoid this hanging 
21 +     dnsmasq. */
22 +
23 +  static int retries = 0;
24 +  struct timespec waiter;
25 +
26     if (errno == EAGAIN || errno == EWOULDBLOCK)
27       {
28         waiter.tv_sec = 0;
29         waiter.tv_nsec = 10000;
30         nanosleep(&waiter, NULL);
31 -       return 1;
32 +       if (retries++ < 1000)
33 +        return 1;
34       }
35 +
36 +   retries = 0;
37     
38     if (errno == EINTR)
39       return 1;
40 -
41 +   
42     return 0;
43  }
44  
45 -- 
46 1.9.1
47