Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/sysctl New sysctl(8) binary. Performs auto-discovery a...
details: https://anonhg.NetBSD.org/src/rev/56cc41d11081
branches: trunk
changeset: 555945:56cc41d11081
user: atatat <atatat%NetBSD.org@localhost>
date: Thu Dec 04 19:49:39 2003 +0000
description:
New sysctl(8) binary. Performs auto-discovery and can add/remove
nodes from the tree. Never needs to be recompiled again.
diffstat:
sbin/sysctl/Makefile | 5 +-
sbin/sysctl/sysctl.c | 2870 ++++++++++++++++++++++++++++-----------------
sbin/sysctl/sysctlutil.c | 518 ++++++++
3 files changed, 2275 insertions(+), 1118 deletions(-)
diffs (truncated from 3564 to 300 lines):
diff -r 78b7cfb2ed90 -r 56cc41d11081 sbin/sysctl/Makefile
--- a/sbin/sysctl/Makefile Thu Dec 04 19:45:19 2003 +0000
+++ b/sbin/sysctl/Makefile Thu Dec 04 19:49:39 2003 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.14 2002/11/30 03:10:54 lukem Exp $
+# $NetBSD: Makefile,v 1.15 2003/12/04 19:49:39 atatat Exp $
# @(#)Makefile 8.1 (Berkeley) 6/6/93
.include <bsd.own.mk>
@@ -6,7 +6,6 @@
PROG= sysctl
MAN= sysctl.8
-CPPFLAGS+=-DINET6 -DIPSEC -I${.CURDIR} -I${NETBSDSRCDIR}/sys
-#CPPFLAGS+=-DTCP6
+SRCS= sysctl.c sysctlutil.c
.include <bsd.prog.mk>
diff -r 78b7cfb2ed90 -r 56cc41d11081 sbin/sysctl/sysctl.c
--- a/sbin/sysctl/sysctl.c Thu Dec 04 19:45:19 2003 +0000
+++ b/sbin/sysctl/sysctl.c Thu Dec 04 19:49:39 2003 +0000
@@ -1,4 +1,36 @@
-/* $NetBSD: sysctl.c,v 1.74 2003/11/10 20:03:29 jonathan Exp $ */
+/* $NetBSD: sysctl.c,v 1.75 2003/12/04 19:49:39 atatat Exp $ */
+
+/*-
+ * Copyright (c) 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Andrew Brown.
+ *
+ * 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. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
/*
* Copyright (c) 1993
@@ -40,238 +72,250 @@
#if 0
static char sccsid[] = "@(#)sysctl.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: sysctl.c,v 1.74 2003/11/10 20:03:29 jonathan Exp $");
+__RCSID("$NetBSD: sysctl.c,v 1.75 2003/12/04 19:49:39 atatat Exp $");
#endif
#endif /* not lint */
+#include <sys/types.h>
#include <sys/param.h>
-#include <sys/gmon.h>
-#include <sys/stat.h>
#include <sys/sysctl.h>
-#include <sys/socket.h>
#include <sys/mount.h>
-#include <sys/mbuf.h>
#include <sys/resource.h>
-#include <uvm/uvm_param.h>
-#include <machine/cpu.h>
-
-#include <ufs/ufs/dinode.h>
-#include <ufs/ufs/dir.h>
-#include <ufs/ffs/fs.h>
-#include <ufs/ffs/ffs_extern.h>
-
+#include <sys/stat.h>
+#include <sys/sched.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/ip_var.h>
+#include <netinet/tcp.h>
+#include <netinet/tcp_timer.h>
+#include <netinet/tcp_var.h>
+#include <netinet/icmp6.h>
#include <nfs/rpcv2.h>
#include <nfs/nfsproto.h>
#include <nfs/nfs.h>
-
-#include <net/if.h>
-
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/ip_icmp.h>
-#include <netinet/icmp_var.h>
-#include <netinet/ip_var.h>
-#include <netinet/udp.h>
-#include <netinet/udp_var.h>
-#include <netinet/tcp.h>
-#include <netinet/tcp_timer.h>
-#include <netinet/tcp_var.h>
+#include <machine/cpu.h>
+#include <netkey/key_var.h>
-#ifdef INET6
-#include <netinet/ip6.h>
-#include <netinet/icmp6.h>
-#include <netinet6/ip6_var.h>
-#include <netinet6/udp6.h>
-#include <netinet6/udp6_var.h>
-#ifdef TCP6
-#include <netinet6/tcp6.h>
-#include <netinet6/tcp6_timer.h>
-#include <netinet6/tcp6_var.h>
-#endif
-#include <netinet6/pim6_var.h>
-#endif /* INET6 */
-
-#include "../../sys/compat/linux/common/linux_exec.h"
-#include "../../sys/compat/irix/irix_sysctl.h"
-#include "../../sys/compat/darwin/darwin_sysctl.h"
-
-#ifdef IPSEC
-#include <net/route.h>
-#include <netinet6/ipsec.h>
-#include <netkey/key_var.h>
-#endif /* IPSEC */
-
-#include <sys/pipe.h>
-
+#include <assert.h>
+#include <ctype.h>
#include <err.h>
-#include <ctype.h>
#include <errno.h>
+#include <inttypes.h>
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
-struct ctlname topname[] = CTL_NAMES;
-struct ctlname kernname[] = CTL_KERN_NAMES;
-struct ctlname vmname[] = CTL_VM_NAMES;
-struct ctlname vfsname[] = CTL_VFS_NAMES;
-struct ctlname netname[] = CTL_NET_NAMES;
-struct ctlname hwname[] = CTL_HW_NAMES;
-struct ctlname username[] = CTL_USER_NAMES;
-struct ctlname ddbname[] = CTL_DDB_NAMES;
-struct ctlname debugname[CTL_DEBUG_MAXID];
-#ifdef CTL_MACHDEP_NAMES
-struct ctlname machdepname[] = CTL_MACHDEP_NAMES;
-#endif
-struct ctlname emulname[] = CTL_EMUL_NAMES;
-struct ctlname vendorname[] = { { 0, 0 } };
+/*
+ * this needs to be able to do the printing and the setting
+ */
+#define HANDLER_PROTO const char *, const char *, char *, \
+ int *, u_int, const struct sysctlnode *, \
+ u_int, void *
+#define HANDLER_ARGS const char *sname, const char *dname, char *value, \
+ int *name, u_int namelen, const struct sysctlnode *pnode, \
+ u_int type, void *v
+#define DISPLAY_VALUE 0
+#define DISPLAY_OLD 1
+#define DISPLAY_NEW 2
-/* this one is dummy, it's used only for '-a' or '-A' */
-struct ctlname procname[] = { {0, 0}, {"curproc", CTLTYPE_NODE} };
+/*
+ * generic routines
+ */
+static struct handlespec *findprinter(const int *, u_int);
+static struct handlespec *findwriter(const int *, u_int);
+static void print_tree(int *, u_int, struct sysctlnode *, u_int, int);
+static void write_number(int *, u_int, struct sysctlnode *, char *);
+static void write_string(int *, u_int, struct sysctlnode *, char *);
+static void display_number(const struct sysctlnode *, const char *,
+ const void *, size_t, int);
+static void display_string(const struct sysctlnode *, const char *,
+ const void *, size_t, int);
+static void display_struct(const struct sysctlnode *, const char *,
+ const void *, size_t, int);
+static void hex_dump(const unsigned char *, size_t);
+static void usage(void);
+static void parse(char *);
+static void cparse(char *);
+static void dparse(char *);
+static void sysctlerror(int);
-char names[BUFSIZ];
+/*
+ * unexported from some place else (XXX tbd)
+ */
+int learn_tree(int *, u_int, struct sysctlnode *);
+
+/*
+ * "handlers"
+ */
+static void printother(HANDLER_PROTO);
+static void kern_clockrate(HANDLER_PROTO);
+static void kern_boottime(HANDLER_PROTO);
+static void kern_consdev(HANDLER_PROTO);
+static void kern_cp_time(HANDLER_PROTO);
+static void vm_loadavg(HANDLER_PROTO);
+static void proc_limit(HANDLER_PROTO);
+#ifdef CPU_DISKINFO
+static void machdep_diskinfo(HANDLER_PROTO);
+#endif /* CPU_DISKINFO */
-struct list {
- struct ctlname *list;
- int size;
-};
-struct list toplist = { topname, CTL_MAXID };
-struct list secondlevel[] = {
- { 0, 0 }, /* CTL_UNSPEC */
- { kernname, KERN_MAXID }, /* CTL_KERN */
- { vmname, VM_MAXID }, /* CTL_VM */
- { vfsname, VFS_MAXID }, /* CTL_VFS */
- { netname, NET_MAXID }, /* CTL_NET */
- { 0, CTL_DEBUG_MAXID }, /* CTL_DEBUG */
- { hwname, HW_MAXID }, /* CTL_HW */
-#ifdef CTL_MACHDEP_NAMES
- { machdepname, CPU_MAXID }, /* CTL_MACHDEP */
-#else
- { 0, 0 }, /* CTL_MACHDEP */
-#endif
- { username, USER_MAXID }, /* CTL_USER_NAMES */
- { ddbname, DDBCTL_MAXID }, /* CTL_DDB_NAMES */
- { procname, 2 }, /* dummy name */
- { vendorname, 0 }, /* CTL_VENDOR_NAMES */
- { emulname, EMUL_MAXID }, /* CTL_EMUL_NAMES */
+struct handlespec {
+ int ps_name[CTL_MAXNAME];
+ void (*ps_p)(HANDLER_PROTO);
+ void (*ps_w)(HANDLER_PROTO);
+ void *ps_d;
+} handlers[] = {
+ { { CTL_KERN, KERN_CLOCKRATE }, kern_clockrate },
+ { { CTL_KERN, KERN_VNODE }, printother, NULL, "pstat" },
+ { { CTL_KERN, KERN_PROC }, printother, NULL, "ps" },
+ { { CTL_KERN, KERN_PROC2 }, printother, NULL, "ps" },
+ { { CTL_KERN, KERN_PROC_ARGS }, printother, NULL, "ps" },
+ { { CTL_KERN, KERN_FILE }, printother, NULL, "pstat" },
+ { { CTL_KERN, KERN_NTPTIME }, printother, NULL,
+ "ntpdc -c kerninfo" },
+ { { CTL_KERN, KERN_MSGBUF }, printother, NULL, "dmesg" },
+ { { CTL_KERN, KERN_BOOTTIME }, kern_boottime },
+ { { CTL_KERN, KERN_CONSDEV }, kern_consdev },
+ { { CTL_KERN, KERN_CP_TIME }, kern_cp_time },
+ { { CTL_KERN, KERN_SYSVIPC_INFO }, printother, NULL, "ipcs" },
+ { { CTL_VM, VM_METER }, printother, NULL,
+ "vmstat' or 'systat" },
+ { { CTL_VM, VM_LOADAVG }, vm_loadavg },
+ { { CTL_VM, VM_UVMEXP }, printother, NULL,
+ "vmstat' or 'systat" },
+ { { CTL_VM, VM_UVMEXP2 }, printother, NULL,
+ "vmstat' or 'systat" },
+ { { CTL_VFS, 2 /* NFS */, NFS_NFSSTATS },
+ printother, NULL, "nfsstat" },
+ { { CTL_NET }, printother, NULL, NULL },
+ { { CTL_NET, PF_LOCAL }, printother, NULL, NULL },
+ { { CTL_NET, PF_INET, IPPROTO_TCP, TCPCTL_IDENT },
+ printother, NULL, "identd" },
+ { { CTL_NET, PF_INET6, IPPROTO_TCP, TCPCTL_IDENT },
+ printother, NULL, "identd" },
- { 0, 0},
+ { { CTL_NET, PF_INET6, IPPROTO_ICMPV6, ICMPV6CTL_ND6_DRLIST },
+ printother, NULL, "something else" },
+ { { CTL_NET, PF_INET6, IPPROTO_ICMPV6, ICMPV6CTL_ND6_PRLIST },
+ printother, NULL, "something else" },
+
+
+ { { CTL_NET, PF_KEY, KEYCTL_DUMPSA },
+ printother, NULL, "setkey" },
+ { { CTL_NET, PF_KEY, KEYCTL_DUMPSP },
+ printother, NULL, "setkey" },
+ /* { { CTL_DEBUG }, printother, NULL, NULL }, */
+ { { CTL_HW, HW_DISKSTATS }, printother, NULL, "iostat" },
+#ifdef CPU_CONSDEV
+ { { CTL_MACHDEP, CPU_CONSDEV }, kern_consdev },
+#endif /* CPU_CONSDEV */
+#ifdef CPU_DISKINFO
+ { { CTL_MACHDEP, CPU_DISKINFO },machdep_diskinfo },
+#endif /* CPU_CONSDEV */
Home |
Main Index |
Thread Index |
Old Index