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.

37 lines
1.2 KiB

  1. From f7cfd36b8a93afd326c0d9378e99576c616bd3fc 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 3/7] 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. --- a/xl2tpd-control.c
  11. +++ b/xl2tpd-control.c
  12. @@ -246,7 +246,7 @@ int main (int argc, char *argv[])
  13. print_error (DEBUG_LEVEL, "command to be passed:\n%s\n", buf);
  14. /* try to open control file for writing */
  15. - int control_fd = open (control_filename, O_WRONLY, 0600);
  16. + int control_fd = open (control_filename, O_WRONLY | O_NONBLOCK, 0600);
  17. if (control_fd < 0)
  18. {
  19. int errorno = errno;
  20. @@ -265,6 +265,14 @@ int main (int argc, char *argv[])
  21. }
  22. return -1;
  23. }
  24. +
  25. + /* turn off O_NONBLOCK */
  26. + if (fcntl (control_fd, F_SETFL, O_WRONLY) == -1) {
  27. + print_error (ERROR_LEVEL,
  28. + "Can not turn off nonblocking mode for control_fd: %s\n",
  29. + strerror(errno));
  30. + return -2;
  31. + }
  32. /* pass command to control pipe */
  33. if (write (control_fd, buf, ftell (mesf)) < 0)