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

  1. From 8c5853b8e22f34bc1c1acba278f7850ab7946894 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 1/7] xl2tpd-control: check end-of-file when reading pipe to
  5. avoid dead loop.
  6. ---
  7. xl2tpd-control.c | 11 +++++++----
  8. 1 file changed, 7 insertions(+), 4 deletions(-)
  9. --- a/xl2tpd-control.c
  10. +++ b/xl2tpd-control.c
  11. @@ -306,17 +306,20 @@ int read_result(int result_fd, char* buf
  12. /*FIXME: there is a chance to hang up reading.
  13. Should I create watching thread with timeout?
  14. */
  15. - ssize_t readed;
  16. + ssize_t readed = 0;
  17. + ssize_t len;
  18. +
  19. do
  20. {
  21. - readed = read (result_fd, buf, size);
  22. - if (readed < 0)
  23. + len = read (result_fd, buf + readed, size - readed);
  24. + if (len < 0)
  25. {
  26. print_error (ERROR_LEVEL,
  27. "error: can't read command result: %s\n", strerror (errno));
  28. break;
  29. }
  30. - } while (readed == 0);
  31. + readed += len;
  32. + } while (len > 0 && (size - readed) > 0);
  33. buf[readed] = '\0';
  34. /* scan result code */