home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / linux / 21043 < prev    next >
Encoding:
Text File  |  1992-12-21  |  1.9 KB  |  74 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!world!jrs
  3. From: jrs@world.std.com (Rick Sladkey)
  4. Subject: GNU make and /proc (was: ps and /dev/kmem)
  5. In-Reply-To: zdenek@ksr.com's message of 18 Dec 92 12:01:57 EST
  6. Message-ID: <JRS.92Dec18220951@lepton.world.std.com>
  7. Sender: jrs@world.std.com (Rick Sladkey)
  8. Organization: The Internet
  9. References: <1992Dec18.063831.24368@news.stolaf.edu> <20234@ksr.com>
  10. Date: Sat, 19 Dec 1992 03:09:51 GMT
  11. Lines: 61
  12.  
  13. >>>>> On 18 Dec 92 12:01:57 EST, zdenek@ksr.com (Zdenek Radouch) said:
  14.  
  15. Zdenek> If you want a really BAD example of what happens when one
  16. Zdenek> hacks /dev/kmem look no further than GNUmake. GNUmake needs
  17. Zdenek> access to the machine loading info, and it was designed to
  18. Zdenek> retrieve it from /dev/kmem rather than using a generic module
  19. Zdenek> that would retrieve it from wherever it can. This resulted in
  20. Zdenek> a design where GNUmake must run with euid=0 (at least at times
  21. Zdenek> that it accesses kmem), and toggle uid back whenever it
  22. Zdenek> touches real files.
  23.  
  24. Linux /proc handles this easily.  Patch for GNU make follows.
  25. -----
  26. *** load.c.orig    Thu Sep 26 04:43:13 1991
  27. --- load.c    Fri Dec 18 22:03:24 1992
  28. ***************
  29. *** 19,24 ****
  30. --- 19,48 ----
  31.   #include "commands.h"
  32.   #include "job.h"
  33.   
  34. + #ifdef linux
  35. + #define LDAV_BASED
  36. + #include <stdlib.h>
  37. + #include <fcntl.h>
  38. + #include <sys/file.h>
  39. + double
  40. + load_average ()
  41. + {
  42. +   static int fd = -1;
  43. +   char buf[32];
  44. +   if (fd == -1 && (fd = open ("/proc/loadavg", O_RDONLY, 0)) < 0)
  45. +       return 0.0;
  46. +   lseek (fd, L_SET, 0);
  47. +   if (read (fd, buf, sizeof (buf)) < 0)
  48. +     return 0.0;
  49. +   return atof(buf);
  50. + }
  51. + #else    /* not linux.  */
  52.   #ifdef UMAX
  53.   
  54.   #define LDAV_BASED
  55. ***************
  56. *** 259,264 ****
  57. --- 283,289 ----
  58.   
  59.   #endif    /* Apollo.  */
  60.   #endif    /* UMAX.  */
  61. + #endif    /* linux.  */
  62.   
  63.   
  64.   #ifdef LDAV_BASED
  65. --
  66. Rick Sladkey
  67. jrs@world.std.com
  68.