bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

proposed getloadavg patch to trim unused parts and speed up 'configure'


From: Paul Eggert
Subject: proposed getloadavg patch to trim unused parts and speed up 'configure'
Date: Mon, 14 Feb 2011 22:32:32 -0800
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7

In modifying GNU Emacs to use getloadavg I noticed that configuring
getloadavg takes too much time, and that this isn't needed.  I
propose the following patch.  It removes support for ancient features
that I think nobody needs any more, namely, getloadavg implementations
that require setgid use, along with the #defines C_GETLOADAVG,
HAVE_GETLOADAVG, and NLIST_NAME_UNION, which nobody should need
any more.  Comments are welcome.

getloadavg: trim unused parts and speed up 'configure'
* NEWS: Document this.
* lib/getloadavg.c: Ignore HAVE_GETLOADAVG; this file is now
always compiled if getloadavg is absent.
Move test code to ...
* tests/test-getloadavg.c: New file, containing previous
contents of test from lib/getloadavg.c.
* modules/getloadavg-tests: New file.
* m4/getloadavg.m4 (gl_GETLOADAVG): Do not check for getloadavg twice.
Do tests in the same order as they're needed for getloadavg.c.
Omit setgid-related tests that generate symbols KMEM_GROUP,
NEET_SETGID, GETLOADAVG_PRIVILEGED; nobody seems to use those any more.
Do only the tests that are needed to see whether the system has
getloadavg, moving the other tests into ...
(gl_PREREQ_GETLOADAVG): ... here.  Do not define obsolete symbol
NLIST_NAME_UNION; nobody should be using it.  Do not define
symbols C_GETLOADAVG and HAVE_GETLOADAVG; they're no longer
relevant, as the user of this module shouldn't care how getloadavg
is implemented.
diff --git a/NEWS b/NEWS
index 13197f7..795488a 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,17 @@ User visible incompatible changes

 Date        Modules         Changes

+2011-02-14  getloadavg      This module no longer #defines C_GETLOADAVG or
+                            HAVE_GETLOADAVG, as the application no longer needs
+                            to worry about how getloadavg is defined.  It no
+                            longer defines the obsolete symbol NLIST_NAME_UNION
+                            (which should have been internal to the module
+                            anyway).  Also, support for setgid use has been
+                            removed, as nobody seems to be using it; thus
+                            GETLOADAVG_PRIVILEGED is no longer #defined and
+                            KMEM_GROUP and NEED_SETGID are no longer
+                            substituted for.
+
 2011-02-08  wctype-h        This module no longer provides the iswblank()
                             function. If you need this function, you now need
                             to request the 'iswblank' module.
diff --git a/lib/getloadavg.c b/lib/getloadavg.c
index 96a6aa4..8e91714 100644
--- a/lib/getloadavg.c
+++ b/lib/getloadavg.c
@@ -94,11 +94,6 @@
 #include <errno.h>
 #include <stdio.h>

-/* Exclude all the code except the test program at the end
-   if the system has its own `getloadavg' function.  */
-
-#ifndef HAVE_GETLOADAVG
-
 # include <sys/types.h>

 /* Both the Emacs and non-Emacs sections want this.  Some
@@ -1032,44 +1027,3 @@ getloadavg (double loadavg[], int nelem)
 # endif
   return elem;
 }
-
-#endif /* ! HAVE_GETLOADAVG */
-
-#ifdef TEST
-int
-main (int argc, char **argv)
-{
-  int naptime = 0;
-
-  if (argc > 1)
-    naptime = atoi (argv[1]);
-
-  while (1)
-    {
-      double avg[3];
-      int loads;
-
-      errno = 0;                /* Don't be misled if it doesn't set errno.  */
-      loads = getloadavg (avg, 3);
-      if (loads == -1)
-        {
-          perror ("Error getting load average");
-          return EXIT_FAILURE;
-        }
-      if (loads > 0)
-        printf ("1-minute: %f  ", avg[0]);
-      if (loads > 1)
-        printf ("5-minute: %f  ", avg[1]);
-      if (loads > 2)
-        printf ("15-minute: %f  ", avg[2]);
-      if (loads > 0)
-        putchar ('\n');
-
-      if (naptime == 0)
-        break;
-      sleep (naptime);
-    }
-
-  return EXIT_SUCCESS;
-}
-#endif /* TEST */
diff --git a/m4/getloadavg.m4 b/m4/getloadavg.m4
index d25ad34..4aae158 100644
--- a/m4/getloadavg.m4
+++ b/m4/getloadavg.m4
@@ -20,90 +20,44 @@ AC_DEFUN([gl_GETLOADAVG],
 # Persuade glibc <stdlib.h> to declare getloadavg().
 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])

-gl_have_func=no # yes means we've found a way to get the load average.
-
 # Make sure getloadavg.c is where it belongs, at configure-time.
 test -f "$srcdir/$1/getloadavg.c" ||
   AC_MSG_ERROR([$srcdir/$1/getloadavg.c is missing])

 gl_save_LIBS=$LIBS

-# Check for getloadavg, but be sure not to touch the cache variable.
-(AC_CHECK_FUNC([getloadavg], [exit 0], [exit 1])) && gl_have_func=yes
-
-# On HPUX9, an unprivileged user can get load averages through this function.
-AC_CHECK_FUNCS([pstat_getdynamic])
-
-# Solaris has libkstat which does not require root.
-AC_CHECK_LIB([kstat], [kstat_open])
-test $ac_cv_lib_kstat_kstat_open = yes && gl_have_func=yes
+AC_CHECK_FUNC([getloadavg], [],
+  [gl_have_func=no
+
+   # Some systems with -lutil have (and need) -lkvm as well, some do not.
+   # On Solaris, -lkvm requires nlist from -lelf, so check that first
+   # to get the right answer into the cache.
+   # For kstat on solaris, we need to test for libelf and libkvm to force the
+   # definition of SVR4 below.
+   if test $gl_have_func = no; then
+     AC_CHECK_LIB([elf], [elf_begin], [LIBS="-lelf $LIBS"])
+     AC_CHECK_LIB([kvm], [kvm_open], [LIBS="-lkvm $LIBS"])
+     # Check for the 4.4BSD definition of getloadavg.
+     AC_CHECK_LIB([util], [getloadavg],
+       [LIBS="-lutil $LIBS" gl_have_func=yes])
+   fi
+
+   if test $gl_have_func = no; then
+     # There is a commonly available library for RS/6000 AIX.
+     # Since it is not a standard part of AIX, it might be installed locally.
+     gl_getloadavg_LIBS=$LIBS
+     LIBS="-L/usr/local/lib $LIBS"
+     AC_CHECK_LIB([getloadavg], [getloadavg],
+                  [LIBS="-lgetloadavg $LIBS" gl_have_func=yes],
+                  [LIBS=$gl_getloadavg_LIBS])
+   fi
+
+   # Set up the replacement function if necessary.
+   if test $gl_have_func = no; then
+     AC_LIBOBJ([getloadavg])
+     gl_PREREQ_GETLOADAVG
+   fi])

-# AIX has libperfstat which does not require root
-AC_CHECK_LIB([perfstat], [perfstat_cpu_total])
-test $ac_cv_lib_perfstat_perfstat_cpu_total = yes && gl_have_func=yes
-
-# Some systems with -lutil have (and need) -lkvm as well, some do not.
-# On Solaris, -lkvm requires nlist from -lelf, so check that first
-# to get the right answer into the cache.
-# For kstat on solaris, we need to test for libelf and libkvm to force the
-# definition of SVR4 below.
-if test $gl_have_func = no; then
-  AC_CHECK_LIB([elf], [elf_begin], [LIBS="-lelf $LIBS"])
-  AC_CHECK_LIB([kvm], [kvm_open], [LIBS="-lkvm $LIBS"])
-  # Check for the 4.4BSD definition of getloadavg.
-  AC_CHECK_LIB([util], [getloadavg],
-    [LIBS="-lutil $LIBS" gl_have_func=yes gl_cv_func_getloadavg_setgid=yes])
-fi
-
-if test $gl_have_func = no; then
-  # There is a commonly available library for RS/6000 AIX.
-  # Since it is not a standard part of AIX, it might be installed locally.
-  gl_getloadavg_LIBS=$LIBS
-  LIBS="-L/usr/local/lib $LIBS"
-  AC_CHECK_LIB([getloadavg], [getloadavg],
-               [LIBS="-lgetloadavg $LIBS"], [LIBS=$gl_getloadavg_LIBS])
-fi
-
-# Make sure it is really in the library, if we think we found it,
-# otherwise set up the replacement function.
-AC_CHECK_FUNCS([getloadavg], [],
-               [gl_PREREQ_GETLOADAVG])
-
-# Some definitions of getloadavg require that the program be installed setgid.
-AC_CACHE_CHECK([whether getloadavg requires setgid],
-               gl_cv_func_getloadavg_setgid,
-[AC_EGREP_CPP([Yowza Am I SETGID yet],
-[#define CONFIGURING_GETLOADAVG
-#include "$srcdir/$1/getloadavg.c"
-#ifdef LDAV_PRIVILEGED
-Yowza Am I SETGID yet
-#endif
-],
-              gl_cv_func_getloadavg_setgid=yes,
-              gl_cv_func_getloadavg_setgid=no)])
-if test $gl_cv_func_getloadavg_setgid = yes; then
-  NEED_SETGID=true
-  AC_DEFINE([GETLOADAVG_PRIVILEGED], [1],
-            [Define to 1 if the `getloadavg' function needs to be run setuid
-             or setgid.])
-else
-  NEED_SETGID=false
-fi
-AC_SUBST([NEED_SETGID])dnl
-
-if test $gl_cv_func_getloadavg_setgid = yes; then
-  AC_CACHE_CHECK([group of /dev/kmem], [gl_cv_group_kmem],
-[ # On Solaris, /dev/kmem is a symlink.  Get info on the real file.
-  ac_ls_output=`ls -lgL /dev/kmem 2>/dev/null`
-  # If we got an error (system does not support symlinks), try without -L.
-  test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem`
-  gl_cv_group_kmem=`echo $ac_ls_output \
-    | sed -ne ['s/[     ][      ]*/ /g
-               s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\)  *.*/\1/
-               / /s/.* //;p']`
-])
-  AC_SUBST([KMEM_GROUP], [$gl_cv_group_kmem])dnl
-fi
 if test "x$gl_save_LIBS" = x; then
   GETLOADAVG_LIBS=$LIBS
 else
@@ -133,14 +87,30 @@ AC_CHECK_DECL([getloadavg], [], [HAVE_DECL_GETLOADAVG=0],
 # --------------------
 # Set up the AC_LIBOBJ replacement of `getloadavg'.
 AC_DEFUN([gl_PREREQ_GETLOADAVG],
-[AC_LIBOBJ([getloadavg])
-AC_DEFINE([C_GETLOADAVG], [1], [Define to 1 if using `getloadavg.c'.])
+[
 # Figure out what our getloadavg.c needs.
-gl_have_func=no
-AC_CHECK_HEADER([sys/dg_sys_info.h],
-[gl_have_func=yes
- AC_DEFINE([DGUX], [1], [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
- AC_CHECK_LIB([dgc], [dg_sys_info])])
+
+# Solaris has libkstat which does not require root.
+AC_CHECK_LIB([kstat], [kstat_open])
+test $ac_cv_lib_kstat_kstat_open = yes && gl_have_func=yes
+
+# On HPUX9, an unprivileged user can get load averages this way.
+if test $gl_have_func = no; then
+  AC_CHECK_FUNCS([pstat_getdynamic], [gl_have_func=yes])
+fi
+
+# AIX has libperfstat which does not require root
+if test $gl_have_func = no; then
+  AC_CHECK_LIB([perfstat], [perfstat_cpu_total])
+  test $ac_cv_lib_perfstat_perfstat_cpu_total = yes && gl_have_func=yes
+fi
+
+if test $gl_have_func = no; then
+  AC_CHECK_HEADER([sys/dg_sys_info.h],
+    [gl_have_func=yes
+     AC_DEFINE([DGUX], [1], [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
+     AC_CHECK_LIB([dgc], [dg_sys_info])])
+fi

 # We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
 # uses stabs), but it is still SVR4.  We cannot check for <elf.h> because
@@ -171,10 +141,7 @@ fi

 AC_CHECK_HEADERS([nlist.h],
 [AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
-                  [AC_DEFINE([NLIST_NAME_UNION], [1],
-                             [Define to 1 if your `struct nlist' has an
-                              `n_un' member.  Obsolete, depend on
-                              `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [],
+                  [], [],
                   address@hidden:@include <nlist.h>])
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <nlist.h>]],
                    [[struct nlist x;
diff --git a/modules/getloadavg-tests b/modules/getloadavg-tests
new file mode 100644
index 0000000..b5ad8cc
--- /dev/null
+++ b/modules/getloadavg-tests
@@ -0,0 +1,11 @@
+Files:
+tests/test-getloadavg.c
+tests/signature.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-getloadavg
+check_PROGRAMS += test-getloadavg
diff --git a/tests/test-getloadavg.c b/tests/test-getloadavg.c
new file mode 100644
index 0000000..1dc0437
--- /dev/null
+++ b/tests/test-getloadavg.c
@@ -0,0 +1,63 @@
+/* Test of getting load average.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <stdlib.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (getloadavg, int, (double [], int));
+
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+
+int
+main (int argc, char **argv)
+{
+  int naptime = 0;
+
+  if (argc > 1)
+    naptime = atoi (argv[1]);
+
+  while (1)
+    {
+      double avg[3];
+      int loads;
+
+      errno = 0;                /* Don't be misled if it doesn't set errno.  */
+      loads = getloadavg (avg, 3);
+      if (loads == -1)
+        {
+          perror ("Skipping test; load average not supported");
+          return 77;
+        }
+      if (loads > 0)
+        printf ("1-minute: %f  ", avg[0]);
+      if (loads > 1)
+        printf ("5-minute: %f  ", avg[1]);
+      if (loads > 2)
+        printf ("15-minute: %f  ", avg[2]);
+      if (loads > 0)
+        putchar ('\n');
+
+      if (naptime == 0)
+        break;
+      sleep (naptime);
+    }
+
+  return 0;
+}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]