/netkit-rusers-0.17-procps.patch

# · Patch · 100 lines · 93 code · 7 blank · 0 comment · 0 complexity · 43e77c779861d8c54a00baf9ba7c2900 MD5 · raw file

  1. --- netkit-rusers-0.17/rpc.rstatd/GNUmakefile.procps 2004-07-12 17:41:48.179608944 +0200
  2. +++ netkit-rusers-0.17/rpc.rstatd/GNUmakefile 2004-07-12 17:41:48.190607585 +0200
  3. @@ -6,10 +6,6 @@
  4. CFLAGS += -DGNU_LIBC -D_GNU_SOURCE
  5. endif
  6. -#LIBS += -lproc
  7. -# XXX FIXME!
  8. -LIBS += /lib/$(shell cd /lib && echo libproc.so.*)
  9. -
  10. RPCGEN=rpcgen
  11. # Warning, do not put this in the current directory without updating
  12. --- netkit-rusers-0.17/rpc.rstatd/rstat_proc.c.procps 2004-07-12 17:41:48.174609561 +0200
  13. +++ netkit-rusers-0.17/rpc.rstatd/rstat_proc.c 2004-07-12 17:55:36.605332290 +0200
  14. @@ -45,6 +45,7 @@
  15. #include <string.h>
  16. #include <signal.h>
  17. #include <fcntl.h>
  18. +#include <locale.h>
  19. #include <limits.h>
  20. #include <rpc/rpc.h>
  21. @@ -596,27 +597,71 @@
  22. #define _DELTA(_x, _i) ( (_x)[(_i)] )
  23. #endif
  24. -extern int uptime(double *, double *);
  25. -extern void loadavg(double *, double *, double *);
  26. -
  27. static void
  28. convert_stats(void)
  29. {
  30. static int tog = 0;
  31. double up;
  32. int i;
  33. + int fd;
  34. + static char buf[1024];
  35. + char *savelocale;
  36. hz = sysconf(_SC_CLK_TCK);
  37. gettimeofday(&tm, (struct timezone *) 0);
  38. - i = uptime(&up, NULL);
  39. + fd = open("/proc/uptime", O_RDONLY);
  40. + if (fd == -1) {
  41. + fprintf(stderr, "Error opening /proc/uptime, please make sure /proc is mounted.\n");
  42. + exit(1);
  43. + }
  44. +
  45. + i = read(fd, buf, sizeof(buf) - 1);
  46. + if (i < 0) {
  47. + perror("/proc/uptime");
  48. + close(fd);
  49. + exit(1);
  50. + }
  51. + buf[i] = '\0';
  52. + savelocale = setlocale(LC_NUMERIC, NULL);
  53. + setlocale(LC_NUMERIC, "C");
  54. + if (sscanf(buf, "%lf", &up) < 1) {
  55. + fprintf(stderr, "bad data in /proc/uptime\n");
  56. + exit(1);
  57. + }
  58. + setlocale(LC_NUMERIC, savelocale);
  59. + close(fd);
  60. +
  61. + i = (int)up;
  62. +
  63. btm.tv_sec = tm.tv_sec - i;
  64. btm.tv_usec = 0;
  65. up -= i;
  66. if (up > 0)
  67. btm.tv_usec = 1000000 * up;
  68. - loadavg(&avrun[0], &avrun[1], &avrun[2]);
  69. + fd = open("/proc/loadavg", O_RDONLY);
  70. + if (fd == -1) {
  71. + fprintf(stderr, "Error opening /proc/loadavg, please make sure /proc is mounted.\n");
  72. + exit(1);
  73. + }
  74. +
  75. + i = read(fd, buf, sizeof(buf) - 1);
  76. + if (i < 0) {
  77. + perror("/proc/loadavg");
  78. + close(fd);
  79. + exit(1);
  80. + }
  81. + buf[i] = '\0';
  82. + savelocale = setlocale(LC_NUMERIC, NULL);
  83. + setlocale(LC_NUMERIC, "C");
  84. + if (sscanf(buf, "%lf %lf %lf", &avrun[0], &avrun[1], &avrun[2]) < 3) {
  85. + fprintf(stderr, "bad data in /proc/loadavg\n");
  86. + exit(1);
  87. + }
  88. + setlocale(LC_NUMERIC, savelocale);
  89. + close(fd);
  90. +
  91. getstat(cpu_use+tog,cpu_nic+tog,cpu_sys+tog,cpu_idl+tog,
  92. pgpgin+tog,pgpgout+tog,pswpin+tog,pswpout+tog,
  93. inter+tog,ticks+tog,ctxt+tog, disk+tog);