X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fgetloadavg.c;h=e9c4c08890203d4ac568b835ba07c7afc265132d;hb=115741fa52092c59e33d75428b776513caa88f87;hp=57e66bab4a89b5bbf2b84083c2629ae7a133eeeb;hpb=cc82de40af8930652f6666f6d495b24fc0730c16;p=gnulib.git diff --git a/lib/getloadavg.c b/lib/getloadavg.c index 57e66bab4..e9c4c0889 100644 --- a/lib/getloadavg.c +++ b/lib/getloadavg.c @@ -1,5 +1,5 @@ /* Get the system load averages. - Copyright (C) 1985, 86, 87, 88, 89, 91, 92, 93, 1994, 1995 + Copyright (C) 1985, 86, 87, 88, 89, 91, 92, 93, 1994, 1995, 1997 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -19,6 +19,14 @@ /* Compile-time symbols that this file uses: + HAVE_PSTAT_GETDYNAMIC Define this if your system has the + pstat_getdynamic function. I think it + is unique to HPUX9. The best way to get the + definition is through the AC_FUNC_GETLOADAVG + macro that comes with autoconf 2.13 or newer. + If that isn't an option, then just put + AC_CHECK_FUNCS(pstat_getdynamic) in your + configure.in file. FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist. KERNEL_FILE Pathname of the kernel to nlist. LDAV_CVT() Scale the load average from the kernel. @@ -43,7 +51,7 @@ DGUX eunice UNIX emulator under VMS. hpux - MSDOS No-op for MSDOS. + __MSDOS__ No-op for MSDOS. NeXT sgi sequent Sequent Dynix 3.x.x (BSD) @@ -52,7 +60,7 @@ UMAX UMAX4_3 VMS - WIN32 No-op for Windows95/NT. + WINDOWS32 No-op for Windows95/NT. __linux__ Linux: assumes /proc filesystem mounted. Support from Michael K. Johnson. __NetBSD__ NetBSD: assumes /kern filesystem mounted. @@ -90,8 +98,14 @@ extern int errno; #endif -#ifndef HAVE_GETLOADAVG +#if HAVE_LOCALE_H +# include +#endif +#if !HAVE_SETLOCALE +# define setlocale(Category, Locale) /* empty */ +#endif +#ifndef HAVE_GETLOADAVG /* The existing Emacs configuration files define a macro called LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and @@ -159,6 +173,9 @@ extern int errno; # if defined (__osf__) && (defined (__alpha) || defined (__alpha__)) # define OSF_ALPHA +# include +# include +# include # include # endif @@ -270,7 +287,7 @@ extern int errno; /* Sometimes both MIPS and sgi are defined, so FSCALE was just defined above under #ifdef MIPS. But we want the sgi value. */ # undef FSCALE -# define FSCALE 1000.0 +# define FSCALE 1000.0 # endif # if defined (ardent) && defined (titan) @@ -288,7 +305,13 @@ extern int errno; # endif /* Not FSCALE. */ # if !defined (LDAV_CVT) && defined (FSCALE) -# define LDAV_CVT(n) (((double) (n)) / FSCALE) +# define LDAV_CVT(n) (((double) (n)) / FSCALE) +# endif + +# ifndef NLIST_STRUCT +# if HAVE_NLIST_H +# define NLIST_STRUCT +# endif # endif /* VAX C can't handle multi-line #ifs, or lines longer that 256 characters. */ @@ -436,6 +459,14 @@ extern int errno; # endif /* LOAD_AVE_TYPE */ +# if defined(__GNU__) && !defined (NeXT) +/* Note that NeXT Openstep defines __GNU__ even though it should not. */ +/* GNU system acts much like NeXT, for load average purposes, + but not exactly. */ +# define NeXT +# define host_self mach_host_self +# endif + # ifdef NeXT # ifdef HAVE_MACH_MACH_H # include @@ -535,7 +566,7 @@ getloadavg (loadavg, nelem) elem = -1; # endif -# if !defined (LDAV_DONE) && defined (SUNOS_5) +# if !defined (LDAV_DONE) && defined (HAVE_LIBKSTAT) /* Use libkstat because we don't have to be root. */ # define LDAV_DONE kstat_ctl_t *kc; @@ -543,10 +574,13 @@ getloadavg (loadavg, nelem) kstat_named_t *kn; kc = kstat_open (); - if (kc == 0) return -1; + if (kc == 0) + return -1; ksp = kstat_lookup (kc, "unix", 0, "system_misc"); - if (ksp == 0 ) return -1; - if (kstat_read (kc, ksp, 0) == -1) return -1; + if (ksp == 0 ) + return -1; + if (kstat_read (kc, ksp, 0) == -1) + return -1; kn = kstat_data_lookup (ksp, "avenrun_1min"); @@ -577,7 +611,7 @@ getloadavg (loadavg, nelem) } kstat_close (kc); -# endif /* SUNOS_5 */ +# endif /* HAVE_LIBKSTAT */ # if !defined (LDAV_DONE) && defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC) /* Use pstat_getdynamic() because we don't have to be root. */ @@ -616,8 +650,11 @@ getloadavg (loadavg, nelem) if (count <= 0) return -1; + /* The following sscanf must use the C locale. */ + setlocale (LC_NUMERIC, "C"); count = sscanf (ldavgbuf, "%lf %lf %lf", &load_ave[0], &load_ave[1], &load_ave[2]); + setlocale (LC_NUMERIC, ""); if (count < 1) return -1; @@ -678,7 +715,7 @@ getloadavg (loadavg, nelem) { info_count = PROCESSOR_SET_BASIC_INFO_COUNT; if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host, - (processor_set_info_t) &info, &info_count) + (processor_set_info_t) &info, &info_count) != KERN_SUCCESS) getloadavg_initialized = 0; else @@ -815,7 +852,7 @@ getloadavg (loadavg, nelem) : (load_ave.tl_avenrun.l[0] / (double) load_ave.tl_lscale)); # endif /* OSF_MIPS */ -# if !defined (LDAV_DONE) && (defined (MSDOS) || defined (WIN32)) +# if !defined (LDAV_DONE) && (defined (__MSDOS__) || defined (WINDOWS32)) # define LDAV_DONE /* A faithful emulation is going to have to be saved for a rainy day. */ @@ -823,7 +860,7 @@ getloadavg (loadavg, nelem) { loadavg[elem] = 0.0; } -# endif /* MSDOS */ +# endif /* __MSDOS__ || WINDOWS32 */ # if !defined (LDAV_DONE) && defined (OSF_ALPHA) # define LDAV_DONE @@ -919,13 +956,13 @@ getloadavg (loadavg, nelem) } # endif /* !SUNOS_5 */ # else /* sgi */ - int ldav_off; + 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)