diff options
author | Jim Meyering <jim@meyering.net> | 2000-11-05 10:12:25 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2000-11-05 10:12:25 +0000 |
commit | 6d722e99e2ec3a3d9325ea815be20a09ecaa0381 (patch) | |
tree | 7f83eb956ba155d47b8e4b4199376a5826ed7e36 | |
parent | 2cac22f76f124b8142e03866024d7c69c8cc9325 (diff) | |
download | coreutils-6d722e99e2ec3a3d9325ea815be20a09ecaa0381.tar.xz |
*** empty log message ***
-rw-r--r-- | lib/tru-knlist-demo.c | 73 |
1 files changed, 51 insertions, 22 deletions
diff --git a/lib/tru-knlist-demo.c b/lib/tru-knlist-demo.c index 578f38a53..1fa65aa8d 100644 --- a/lib/tru-knlist-demo.c +++ b/lib/tru-knlist-demo.c @@ -5,37 +5,66 @@ #include <string.h> #include <stdlib.h> #include <nlist.h> + +#ifndef FD_CLOEXEC +# define FD_CLOEXEC 1 +#endif + +#ifndef LDAV_SYMBOL +# define LDAV_SYMBOL "_avenrun" +#endif + +int main () { - struct nlist nl[3]; - int retval, i; - nl[0].n_name = (char *)malloc(10); - nl[1].n_name = (char *)malloc(10); - nl[2].n_name = ""; + struct nlist nl[2]; + int retval; + long offset; - /*******************************************************/ - /* Store names of kernel symbols in the nl array */ - strcpy (nl[0].n_name, "ncpus"); - strcpy (nl[1].n_name, "lockmode"); + nl[0].n_name = LDAV_SYMBOL; + nl[1].n_name = ""; /*******************************************************/ /* Call the knlist routine */ - retval = knlist(nl); + retval = knlist (nl); /******************************************************/ /* Display addresses if returned. Otherwise, display */ /* the appropriate error message. */ if (retval < 0) - printf ("No kernel symbol addresses returned.\n"); - else - if (retval >= 0 ) - for (i=0; i<2; i++) - if (nl[i].n_type == 0) - printf ("Unable to return address of symbol %s\n", - nl[i].n_name); - else - printf ("The address of symbol %s is %lx\n", - nl[i].n_name, nl[i].n_value); - free (nl[0].n_name); - free (nl[1].n_name); + { + printf ("No kernel symbol addresses returned.\n"); + exit (1); + } + + if (nl[0].n_type == 0) + { + printf ("Unable to return address of symbol %s\n", nl[0].n_name); + exit (1); + } + + offset = nl[0].n_value; + printf ("The address of symbol %s is %lx\n", nl[0].n_name, offset); + + { + double load_ave[3]; + int channel = open ("/dev/kmem", 0); + if (channel < 0) + { + printf ("open failed\n"); + exit (1); + } +#ifdef FD_SETFD + (void) fcntl (channel, F_SETFD, FD_CLOEXEC); +#endif + + if (lseek (channel, offset, 0) == -1L + || read (channel, (char *) load_ave, sizeof (load_ave)) + != sizeof (load_ave)) + { + close (channel); + } + } + + exit (0); } |