You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.3 KiB

  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. Otherwise xl2tpd-control would block indefinitely in case xl2tpd is
  6. not running.
  7. ---
  8. xl2tpd-control.c | 10 +++++++++-
  9. 1 file changed, 9 insertions(+), 1 deletion(-)
  10. diff --git a/xl2tpd-control.c b/xl2tpd-control.c
  11. index 9b6235d..973ee87 100644
  12. --- a/xl2tpd-control.c
  13. +++ b/xl2tpd-control.c
  14. @@ -246,7 +246,7 @@ int main (int argc, char *argv[])
  15. print_error (DEBUG_LEVEL, "command to be passed:\n%s\n", buf);
  16. /* try to open control file for writing */
  17. - int control_fd = open (control_filename, O_WRONLY, 0600);
  18. + int control_fd = open (control_filename, O_WRONLY | O_NONBLOCK, 0600);
  19. if (control_fd < 0)
  20. {
  21. int errorno = errno;
  22. @@ -265,6 +265,14 @@ int main (int argc, char *argv[])
  23. }
  24. return -1;
  25. }
  26. +
  27. + /* turn off O_NONBLOCK */
  28. + if (fcntl (control_fd, F_SETFL, O_WRONLY) == -1) {
  29. + print_error (ERROR_LEVEL,
  30. + "Can not turn off nonblocking mode for control_fd: %s\n",
  31. + strerror(errno));
  32. + return -2;
  33. + }
  34. /* pass command to control pipe */
  35. if (write (control_fd, buf, ftell (mesf)) < 0)
  36. --
  37. 1.7.10.4