]> code.delx.au - gnu-emacs/blobdiff - src/getloadavg.c
Declare calloc like malloc.
[gnu-emacs] / src / getloadavg.c
index 9bf992b4b58fb9314413c1fe5944e4bc447fec8f..7f939d2dbe4846510f6aff08b011c9a52c6f40b7 100644 (file)
@@ -1,5 +1,5 @@
 /* Get the system load averages.
-   Copyright (C) 1985, 86, 87, 88, 89, 91, 92, 93, 1994
+   Copyright (C) 1985, 86, 87, 88, 89, 91, 92, 93, 1994, 1995
        Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
@@ -38,6 +38,7 @@
 
    apollo
    BSD                         Real BSD, not just BSD-like.
+   convex
    DGUX
    eunice                      UNIX emulator under VMS.
    hpux
    We also #define LDAV_PRIVILEGED if a program will require
    special installation to be able to call getloadavg.  */
 
+/* This should always be first.  */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <sys/types.h>
 
 /* Both the Emacs and non-Emacs sections want this.  Some
 #endif
 
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 /* Exclude all the code except the test program at the end
    if the system has its own `getloadavg' function.
 
@@ -209,6 +211,17 @@ extern int errno;
 #define LOAD_AVE_TYPE long
 #endif
 
+#ifdef _AIX
+#define LOAD_AVE_TYPE long
+#endif
+
+#ifdef convex
+#define LOAD_AVE_TYPE double
+#ifndef LDAV_CVT
+#define LDAV_CVT(n) (n)
+#endif
+#endif
+
 #endif /* No LOAD_AVE_TYPE.  */
 
 #ifdef OSF_ALPHA
@@ -218,6 +231,13 @@ extern int errno;
 #define FSCALE 1024.0
 #endif
 
+#if defined(alliant) && defined(i860) /* Alliant FX/2800 */
+/* <sys/param.h> defines an incorrect value for FSCALE on an
+   Alliant FX/2800 Concentrix 2.2, according to ghazi@noc.rutgers.edu.  */
+#undef FSCALE
+#define FSCALE 100.0
+#endif
+
 
 #ifndef        FSCALE
 
@@ -246,11 +266,8 @@ extern int errno;
 #define FSCALE 100.0
 #endif
 
-#if defined(alliant) && defined(i860) /* Alliant FX/2800 */
-/* <sys/param.h> defines an incorrect value for FSCALE on an
-   Alliant FX/2800 Concentrix 2.2, according to ghazi@noc.rutgers.edu.  */
-#undef FSCALE
-#define FSCALE 100.0
+#ifdef _AIX
+#define FSCALE 65536.0
 #endif
 
 #endif /* Not FSCALE.  */
@@ -314,6 +331,10 @@ extern int errno;
 #define NLIST_STRUCT
 #endif
 
+#ifdef _AIX
+#define NLIST_STRUCT
+#endif
+
 #endif /* defined (NLIST_STRUCT) */
 
 
@@ -339,7 +360,7 @@ extern int errno;
 #define LDAV_SYMBOL "_Loadavg"
 #endif
 
-#if !defined(LDAV_SYMBOL) && ((defined(hpux) && !defined(hp9000s300)) || defined(_SEQUENT_) || defined(SVR4) || defined(ISC) || defined(sgi) || (defined (ardent) && defined (titan)))
+#if !defined(LDAV_SYMBOL) && ((defined(hpux) && !defined(hp9000s300)) || defined(_SEQUENT_) || defined(SVR4) || defined(ISC) || defined(sgi) || (defined (ardent) && defined (titan)) || defined (_AIX))
 #define LDAV_SYMBOL "avenrun"
 #endif
 
@@ -789,23 +810,29 @@ getloadavg (loadavg, nelem)
 #endif /* NLIST_STRUCT */
 
 #ifndef SUNOS_5
-      if (nlist (KERNEL_FILE, nl) >= 0)
-       /* Omit "&& nl[0].n_type != 0 " -- it breaks on Sun386i.  */
-       {
+      if (
+#if !(defined (_AIX) && !defined (ps2))
+         nlist (KERNEL_FILE, nl)
+#else  /* _AIX */
+         knlist (nl, 1, sizeof (nl[0]))
+#endif
+         >= 0)
+         /* Omit "&& nl[0].n_type != 0 " -- it breaks on Sun386i.  */
+         {
 #ifdef FIXUP_KERNEL_SYMBOL_ADDR
-         FIXUP_KERNEL_SYMBOL_ADDR (nl);
+           FIXUP_KERNEL_SYMBOL_ADDR (nl);
 #endif
-         offset = nl[0].n_value;
-       }
-#endif  /* !SUNOS_5 */
-#else /* sgi */
-      int ldav_off;
+           offset = nl[0].n_value;
+         }
+#endif /* !SUNOS_5 */
+#else  /* sgi */
+         int ldav_off;
 
-      ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN);
-      if (ldav_off != -1)
-       offset = (long) ldav_off & 0x7fffffff;
+         ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN);
+         if (ldav_off != -1)
+         offset = (long) ldav_off & 0x7fffffff;
 #endif /* sgi */
-    }
+       }
 
   /* Make sure we have /dev/kmem open.  */
   if (!getloadavg_initialized)
@@ -813,7 +840,17 @@ getloadavg (loadavg, nelem)
 #ifndef SUNOS_5
       channel = open ("/dev/kmem", 0);
       if (channel >= 0)
-       getloadavg_initialized = 1;
+       {
+         /* Set the channel to close on exec, so it does not
+            litter any child's descriptor table.  */
+#ifdef FD_SETFD
+#ifndef FD_CLOEXEC
+#define FD_CLOEXEC 1
+#endif
+         (void) fcntl (channel, F_SETFD, FD_CLOEXEC);
+#endif
+         getloadavg_initialized = 1;
+       }
 #else /* SUNOS_5 */
       /* We pass 0 for the kernel, corefile, and swapfile names
         to use the currently running kernel.  */