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.2 KiB

  1. From 7973d45a0e1716ddc6bfb6caf600f826f59a7932 Mon Sep 17 00:00:00 2001
  2. From: Yousong Zhou <yszhou4tech@gmail.com>
  3. Date: Tue, 28 Apr 2015 21:26:15 +0800
  4. Subject: [PATCH 200/210] xl2tpd-control: check end-of-file when reading pipe
  5. to avoid dead loop.
  6. ---
  7. xl2tpd-control.c | 11 +++++++----
  8. 1 file changed, 7 insertions(+), 4 deletions(-)
  9. diff --git a/xl2tpd-control.c b/xl2tpd-control.c
  10. index feafe10..e5904d8 100644
  11. --- a/xl2tpd-control.c
  12. +++ b/xl2tpd-control.c
  13. @@ -306,17 +306,20 @@ int read_result(int result_fd, char* buf, ssize_t size)
  14. /*FIXME: there is a chance to hang up reading.
  15. Should I create watching thread with timeout?
  16. */
  17. - ssize_t readed;
  18. + ssize_t readed = 0;
  19. + ssize_t len;
  20. +
  21. do
  22. {
  23. - readed = read (result_fd, buf, size);
  24. - if (readed < 0)
  25. + len = read (result_fd, buf + readed, size - readed);
  26. + if (len < 0)
  27. {
  28. print_error (ERROR_LEVEL,
  29. "error: can't read command result: %s\n", strerror (errno));
  30. break;
  31. }
  32. - } while (readed == 0);
  33. + readed += len;
  34. + } while (len > 0 && (size - readed) > 0);
  35. buf[readed] = '\0';
  36. /* scan result code */
  37. --
  38. 1.7.10.4