From d299a6422b15628e7a2b44727af454bc99f41911 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Tue, 14 Sep 2010 21:31:56 +0000 Subject: [PATCH] make all other commands use ProcFS --- benchmarks/unixbench-5.1.2/src/whets.c | 4 +- commands/autopart/autopart.c | 6 +-- commands/lspci/Makefile | 2 +- commands/lspci/lspci.c | 53 -------------------------- commands/lspci/lspci.sh | 8 ++++ commands/service/service.c | 8 +--- commands/tcpstat/tcpstat.c | 3 +- commands/time/time.c | 3 +- test/test41.c | 3 +- test/test44.c | 6 +-- 10 files changed, 19 insertions(+), 77 deletions(-) delete mode 100644 commands/lspci/lspci.c create mode 100644 commands/lspci/lspci.sh diff --git a/benchmarks/unixbench-5.1.2/src/whets.c b/benchmarks/unixbench-5.1.2/src/whets.c index cfeef82f6..8a5948507 100644 --- a/benchmarks/unixbench-5.1.2/src/whets.c +++ b/benchmarks/unixbench-5.1.2/src/whets.c @@ -932,9 +932,9 @@ SPDP dtime() return q; } #else +#include #include #include -#include #include struct tms tms; @@ -945,7 +945,7 @@ SPDP dtime(void) int secs, msecs; u32_t system_hz; times(&tms); - getsysinfo_up(PM_PROC_NR, SIU_SYSTEMHZ, sizeof(system_hz), &system_hz); + system_hz = (u32_t) sysconf(_SC_CLK_TCK); secs = tms.tms_utime / system_hz; q = secs; tms.tms_utime -= secs * system_hz; diff --git a/commands/autopart/autopart.c b/commands/autopart/autopart.c index bbf656334..6d1ebaf68 100644 --- a/commands/autopart/autopart.c +++ b/commands/autopart/autopart.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -1597,10 +1596,7 @@ void m_read(int ev, int *biosdrive) return; } - if(getsysinfo_up(PM_PROC_NR, SIU_SYSTEMHZ, sizeof(system_hz), &system_hz) < 0) { - fprintf(stderr, "autopart: system hz not found\n"); - exit(1); - } + system_hz = (u32_t) sysconf(_SC_CLK_TCK); v = 2*system_hz; ioctl(device, DIOCTIMEOUT, &v); diff --git a/commands/lspci/Makefile b/commands/lspci/Makefile index aed9e34a3..bc82f474d 100644 --- a/commands/lspci/Makefile +++ b/commands/lspci/Makefile @@ -1,4 +1,4 @@ -PROG= lspci +SCRIPTS= lspci.sh MAN= .include diff --git a/commands/lspci/lspci.c b/commands/lspci/lspci.c deleted file mode 100644 index ae9db7554..000000000 --- a/commands/lspci/lspci.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2009, Erik van der Kouwe - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -int main(int argc, char **argv) -{ - struct pciinfo_entry *entry; - struct pciinfo pciinfo; - - /* obtain a list of PCI devices from PM */ - if (getsysinfo(PM_PROC_NR, SI_PCI_INFO, &pciinfo) < 0) - { - perror("getsysinfo failed"); - return -1; - } - - /* print the list of devices */ - entry = pciinfo.pi_entries; - while (pciinfo.pi_count-- > 0) - { - printf("%.4X:%.4X %s\n", entry->pie_vid, entry->pie_did, entry->pie_name); - entry++; - } - - return 0; -} diff --git a/commands/lspci/lspci.sh b/commands/lspci/lspci.sh new file mode 100644 index 000000000..a4c3bc0ab --- /dev/null +++ b/commands/lspci/lspci.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +if [ ! -f /proc/pci ]; then + echo "PCI list not found (is /proc mounted?)" >&2 + exit 1 +fi + +exec cut -d' ' -f3- /proc/pci diff --git a/commands/service/service.c b/commands/service/service.c index 7b44d7342..f7726854e 100644 --- a/commands/service/service.c +++ b/commands/service/service.c @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -277,12 +276,7 @@ PRIVATE int parse_arguments(int argc, char **argv) } /* Get HZ. */ - if(getsysinfo_up(PM_PROC_NR, - SIU_SYSTEMHZ, sizeof(system_hz), &system_hz) < 0) { - system_hz = DEFAULT_HZ; - fprintf(stderr, "WARNING: reverting to default HZ %d\n", - (int) system_hz); - } + system_hz = (u32_t) sysconf(_SC_CLK_TCK); /* Check optional arguments that come in pairs like "-args arglist". */ for (i=optind+MIN_ARG_COUNT+1; i #include #include #include -#include #include #include @@ -55,7 +54,7 @@ int main(int argc, char*argv[]) int a_flag, n_flag, v_flag; struct tms tmsbuf; - getsysinfo_up(PM_PROC_NR, SIU_SYSTEMHZ, sizeof(system_hz), &system_hz); + system_hz = (u32_t) sysconf(_SC_CLK_TCK); (prog_name=strrchr(argv[0], '/')) ? prog_name++ : (prog_name=argv[0]); diff --git a/commands/time/time.c b/commands/time/time.c index 7860062b5..a2e038265 100644 --- a/commands/time/time.c +++ b/commands/time/time.c @@ -11,7 +11,6 @@ #include #include #include -#include #include /* -DNEW prints time to 0.01 sec. */ @@ -111,7 +110,7 @@ register clock_t t; int hours, minutes, seconds, hundredths, i; u32_t system_hz; - getsysinfo_up(PM_PROC_NR, SIU_SYSTEMHZ, sizeof(system_hz), &system_hz); + system_hz = (u32_t) sysconf(_SC_CLK_TCK); digit_seen = 0; for (i = 0; i < 8; i++) a[i] = ' '; diff --git a/test/test41.c b/test/test41.c index 2a0bc1064..02f1fdd47 100644 --- a/test/test41.c +++ b/test/test41.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -72,7 +71,7 @@ char **argv; { int i, m = 0xFFFF, n = 0xF; - getsysinfo_up(PM_PROC_NR, SIU_SYSTEMHZ, sizeof(system_hz), &system_hz); + system_hz = sysconf(_SC_CLK_TCK); if (strcmp(argv[0], "DO CHECK") == 0) { timer = atoi(argv[1]); diff --git a/test/test44.c b/test/test44.c index 96aff0ef3..9bf3a0098 100644 --- a/test/test44.c +++ b/test/test44.c @@ -4,7 +4,6 @@ #include #include #include -#include #include #include @@ -15,6 +14,7 @@ main(int argc, char *argv[]) #define CHUNKS1 3 #define CHUNKS2 2 #define CHUNKS (CHUNKS1+CHUNKS2) +#define LARGESIZE 262144 int i, fd; char *v[CHUNKS]; #define STARTV 0x90000000 @@ -86,11 +86,11 @@ main(int argc, char *argv[]) exit(1); } } else { - /* Child performs bogus getsysinfo */ + /* Child performs bogus read */ int res; char *buf = v[CHUNKS-1]; errno = 0; - res = getsysinfo( PM_PROC_NR, SI_PROC_TAB, buf); + res = read(fd, buf, LARGESIZE); if(res >= 0) { fprintf(stderr, "res %d\n", res); exit(1); -- 2.44.0