|
From f7cfd36b8a93afd326c0d9378e99576c616bd3fc Mon Sep 17 00:00:00 2001
|
|
From: Yousong Zhou <yszhou4tech@gmail.com>
|
|
Date: Wed, 29 Apr 2015 14:21:12 +0800
|
|
Subject: [PATCH 3/7] xl2tpd-control: open control file with O_NONBLOCK.
|
|
|
|
Otherwise xl2tpd-control would block indefinitely in case xl2tpd is
|
|
not running.
|
|
---
|
|
xl2tpd-control.c | 10 +++++++++-
|
|
1 file changed, 9 insertions(+), 1 deletion(-)
|
|
|
|
--- a/xl2tpd-control.c
|
|
+++ b/xl2tpd-control.c
|
|
@@ -246,7 +246,7 @@ int main (int argc, char *argv[])
|
|
print_error (DEBUG_LEVEL, "command to be passed:\n%s\n", buf);
|
|
|
|
/* try to open control file for writing */
|
|
- int control_fd = open (control_filename, O_WRONLY, 0600);
|
|
+ int control_fd = open (control_filename, O_WRONLY | O_NONBLOCK, 0600);
|
|
if (control_fd < 0)
|
|
{
|
|
int errorno = errno;
|
|
@@ -265,6 +265,14 @@ int main (int argc, char *argv[])
|
|
}
|
|
return -1;
|
|
}
|
|
+
|
|
+ /* turn off O_NONBLOCK */
|
|
+ if (fcntl (control_fd, F_SETFL, O_WRONLY) == -1) {
|
|
+ print_error (ERROR_LEVEL,
|
|
+ "Can not turn off nonblocking mode for control_fd: %s\n",
|
|
+ strerror(errno));
|
|
+ return -2;
|
|
+ }
|
|
|
|
/* pass command to control pipe */
|
|
if (write (control_fd, buf, ftell (mesf)) < 0)
|