Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Jul 1996 13:54:40 +0000 ()
From:      James Raynard <fqueries@jraynard.demon.co.uk>
To:        Gary Palmer <gpalmer@freebsd.org>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: gmake 3.74 port setgid kmem
Message-ID:  <199607231354.NAA17597@jraynard.demon.co.uk>
In-Reply-To: <10843.838092883@orion.webspan.net> from "Gary Palmer" at Jul 22, 96 11:34:43 pm

next in thread | previous in thread | raw e-mail | index | archive | help

> 
> Nate Williams wrote in message ID
> <199607221939.NAA21664@rocky.mt.sri.com>:
> > One of the 'features' of gmake is the ability to 'stop compiling' until
> > the load average of the machine goes down to an acceptable level, so it
> > needs permissions to read /dev/mem to determine the load average.
> 
> > I consider it's setgid-ness along with the 'load average' bit to be a
> > mis-feature.
 
Very much so.

> It most definately is, considering you can read the load ave stuff
> with sysctl, and not go ANYWHERE NEAR /dev/mem... since it's a port,
> it shouldn't be TOO difficult to do this.

Writing code to do this is easy, hacking configure so that the code
actually gets called instead of getloadavg() is a little harder...

--- getloadavg.c.orig	Tue Jul 23 12:36:11 1996
+++ getloadavg.c	Tue Jul 23 13:20:54 1996
@@ -52,6 +52,7 @@
    __linux__			Linux: assumes /proc filesystem mounted.
    				Support from Michael K. Johnson.
    __NetBSD__			NetBSD: assumes /kern filesystem mounted.
+   __FreeBSD__
 
    In addition, to avoid nesting many #ifdefs, we internally set
    LDAV_DONE to indicate that the load average has been computed.
@@ -504,6 +505,33 @@
   errno = 0;
   elem = -1;
 #endif
+
+#if !defined (LDAV_DONE) && defined (__FreeBSD__)
+#define LDAV_DONE
+#undef LOAD_AVE_TYPE
+
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/sysctl.h>
+#include <vm/vm_param.h>
+
+  struct loadavg load_ave;
+  int mib[2];
+  size_t len;
+
+  mib[0] = CTL_VM;
+  mib[1] = VM_LOADAVG;
+  len = sizeof(load_ave);
+
+  if (sysctl(mib, 2, &load_ave, &len, NULL, 0) < 0)
+    return -1;
+
+  for (elem = 0; elem < nelem; elem++)
+    loadavg[elem] = (double)load_ave.ldavg[elem]/(double)load_ave.fscale;
+
+  return elem;
+
+#endif /* __FreeBSD__ */
 
 #if !defined (LDAV_DONE) && defined (__linux__)
 #define LDAV_DONE

Script started on Tue Jul 23 13:22:21 1996
# make check-loadavg
The system uptime program believes the load average to be:
uptime
 1:22PM  up  4:35, 4 users, load averages: 0.02, 0.12, 0.12
The GNU load average checking code believes:
./loadavg
1-minute: 0.020020  5-minute: 0.120605  15-minute: 0.119141  
# ^D
Script done on Tue Jul 23 13:22:32 1996




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199607231354.NAA17597>