home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.linux
- Path: sparky!uunet!world!jrs
- From: jrs@world.std.com (Rick Sladkey)
- Subject: GNU make and /proc (was: ps and /dev/kmem)
- In-Reply-To: zdenek@ksr.com's message of 18 Dec 92 12:01:57 EST
- Message-ID: <JRS.92Dec18220951@lepton.world.std.com>
- Sender: jrs@world.std.com (Rick Sladkey)
- Organization: The Internet
- References: <1992Dec18.063831.24368@news.stolaf.edu> <20234@ksr.com>
- Date: Sat, 19 Dec 1992 03:09:51 GMT
- Lines: 61
-
- >>>>> On 18 Dec 92 12:01:57 EST, zdenek@ksr.com (Zdenek Radouch) said:
-
- Zdenek> If you want a really BAD example of what happens when one
- Zdenek> hacks /dev/kmem look no further than GNUmake. GNUmake needs
- Zdenek> access to the machine loading info, and it was designed to
- Zdenek> retrieve it from /dev/kmem rather than using a generic module
- Zdenek> that would retrieve it from wherever it can. This resulted in
- Zdenek> a design where GNUmake must run with euid=0 (at least at times
- Zdenek> that it accesses kmem), and toggle uid back whenever it
- Zdenek> touches real files.
-
- Linux /proc handles this easily. Patch for GNU make follows.
- -----
- *** load.c.orig Thu Sep 26 04:43:13 1991
- --- load.c Fri Dec 18 22:03:24 1992
- ***************
- *** 19,24 ****
- --- 19,48 ----
- #include "commands.h"
- #include "job.h"
-
- + #ifdef linux
- +
- + #define LDAV_BASED
- +
- + #include <stdlib.h>
- + #include <fcntl.h>
- + #include <sys/file.h>
- +
- + double
- + load_average ()
- + {
- + static int fd = -1;
- + char buf[32];
- +
- + if (fd == -1 && (fd = open ("/proc/loadavg", O_RDONLY, 0)) < 0)
- + return 0.0;
- + lseek (fd, L_SET, 0);
- + if (read (fd, buf, sizeof (buf)) < 0)
- + return 0.0;
- + return atof(buf);
- + }
- +
- + #else /* not linux. */
- +
- #ifdef UMAX
-
- #define LDAV_BASED
- ***************
- *** 259,264 ****
- --- 283,289 ----
-
- #endif /* Apollo. */
- #endif /* UMAX. */
- + #endif /* linux. */
-
-
- #ifdef LDAV_BASED
- --
- Rick Sladkey
- jrs@world.std.com
-