002-uclibc_loadavg.patch 917 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. --- a/src/libs/zbxsysinfo/linux/cpu.c
  2. +++ b/src/libs/zbxsysinfo/linux/cpu.c
  3. @@ -22,6 +22,45 @@
  4. #include "stats.h"
  5. #include "log.h"
  6. +
  7. +/* uclibc and dietlibc do not have this junk -ReneR */
  8. +#if defined (__UCLIBC__) || defined (__dietlibc__)
  9. +static int getloadavg (double loadavg[], int nelem)
  10. +{
  11. + int fd;
  12. +
  13. + fd = open ("/proc/loadavg", O_RDONLY);
  14. + if (fd < 0)
  15. + return -1;
  16. + else
  17. + {
  18. + char buf[65], *p;
  19. + ssize_t nread;
  20. + int i;
  21. +
  22. + nread = read (fd, buf, sizeof buf - 1);
  23. + close (fd);
  24. + if (nread <= 0)
  25. + return -1;
  26. + buf[nread - 1] = '\0';
  27. +
  28. + if (nelem > 3)
  29. + nelem = 3;
  30. + p = buf;
  31. + for (i = 0; i < nelem; ++i)
  32. + {
  33. + char *endp;
  34. + loadavg[i] = strtod (p, &endp);
  35. + if (endp == p)
  36. + return -1;
  37. + p = endp;
  38. + }
  39. +
  40. + return i;
  41. + }
  42. +}
  43. +#endif
  44. +
  45. int SYSTEM_CPU_NUM(AGENT_REQUEST *request, AGENT_RESULT *result)
  46. {
  47. char *type;