xl2tpd: conditionally build with flags for more verbose log output.
[feed/packages.git] / net / xl2tpd / patches / 202-xl2tpd-control-open-control-file-with-O_NONBLOCK.patch
1 From fedfd6685e5f81f0460beb4c448a30e7a6cfbd31 Mon Sep 17 00:00:00 2001
2 From: Yousong Zhou <yszhou4tech@gmail.com>
3 Date: Wed, 29 Apr 2015 14:21:12 +0800
4 Subject: [PATCH 202/210] xl2tpd-control: open control file with O_NONBLOCK.
5
6 Otherwise xl2tpd-control would block indefinitely in case xl2tpd is
7 not running.
8 ---
9 xl2tpd-control.c | 10 +++++++++-
10 1 file changed, 9 insertions(+), 1 deletion(-)
11
12 diff --git a/xl2tpd-control.c b/xl2tpd-control.c
13 index 9b6235d..973ee87 100644
14 --- a/xl2tpd-control.c
15 +++ b/xl2tpd-control.c
16 @@ -246,7 +246,7 @@ int main (int argc, char *argv[])
17 print_error (DEBUG_LEVEL, "command to be passed:\n%s\n", buf);
18
19 /* try to open control file for writing */
20 - int control_fd = open (control_filename, O_WRONLY, 0600);
21 + int control_fd = open (control_filename, O_WRONLY | O_NONBLOCK, 0600);
22 if (control_fd < 0)
23 {
24 int errorno = errno;
25 @@ -265,6 +265,14 @@ int main (int argc, char *argv[])
26 }
27 return -1;
28 }
29 +
30 + /* turn off O_NONBLOCK */
31 + if (fcntl (control_fd, F_SETFL, O_WRONLY) == -1) {
32 + print_error (ERROR_LEVEL,
33 + "Can not turn off nonblocking mode for control_fd: %s\n",
34 + strerror(errno));
35 + return -2;
36 + }
37
38 /* pass command to control pipe */
39 if (write (control_fd, buf, ftell (mesf)) < 0)
40 --
41 1.7.10.4
42