1 From 97adf987cf230e47a4800c2f0a0940a1d0d98109 Mon Sep 17 00:00:00 2001
2 From: wendy2001011 <wendy2001011@163.com>
3 Date: Thu, 9 Feb 2017 17:32:14 +0800
4 Subject: [PATCH] xl2tpd-control: fix xl2tpd hanged up in "fopen"
6 This is a fix for xl2tpd hanged up in "fopen" result fifo while working
7 on xl2tpd with OpenWrt.
9 Root cause is as followings,
10 1. xl2tpd-control open result fifo ##fifo readers=1
11 2. xl2tpd-control read result fifo
12 3. xl2tpd-control close result fifo ##fifo readers=0
13 4. xl2tpd fopen result fifo ##xl2tpd is hanged up here to wait readers
14 5. xl2tpd-control unlink result fifo
16 The fix replaces the order of "unlink" and "close" when cleaning up to
17 avoid hang up issue in fopen, and add the retry waiting when reading
20 [Yousong Zhou: 2s as the timeout and 10ms as the check interval]
22 xl2tpd-control.c | 23 +++++++++++++++++++++--
23 1 file changed, 21 insertions(+), 2 deletions(-)
25 diff --git a/xl2tpd-control.c b/xl2tpd-control.c
26 index 9fcab76..b8bf822 100644
27 --- a/xl2tpd-control.c
28 +++ b/xl2tpd-control.c
31 #define TUNNEL_REQUIRED 1
32 #define TUNNEL_NOT_REQUIRED 0
33 +#define TIMEOUT 2000000 //timeout is 2s
35 char result_filename[128];
37 @@ -149,9 +150,9 @@ void help()
43 unlink (result_filename);
48 int main (int argc, char *argv[])
49 @@ -340,6 +341,7 @@ void print_error (int level, const char *fmt, ...)
54 int read_result(int result_fd, char* buf, ssize_t size)
56 /* read result from result_fd */
57 @@ -348,6 +350,11 @@ int read_result(int result_fd, char* buf, ssize_t size)
65 + gettimeofday(&tvs, NULL);
69 @@ -360,8 +367,20 @@ int read_result(int result_fd, char* buf, ssize_t size)
70 "error: can't read command result: %s\n", strerror (errno));
72 } else if (len == 0) {
74 + gettimeofday(&tve, NULL);
75 + diff = (tve.tv_sec - tvs.tv_sec) * 1000000 + (tve.tv_usec - tvs.tv_usec);
76 + if (diff >= TIMEOUT) {
77 + print_error (DEBUG_LEVEL, "error: read timout\n");
88 if ((size - readed) <= 0)