aboutsummaryrefslogtreecommitdiff
path: root/sbin/sysctl
diff options
context:
space:
mode:
authorAndrew Gallatin <gallatin@FreeBSD.org>2017-07-31 14:56:35 +0000
committerAndrew Gallatin <gallatin@FreeBSD.org>2017-07-31 14:56:35 +0000
commita18f34fe7787ddda9447ae4be28d68c2f57a7031 (patch)
tree78efddf7f8099948b79f6280ba8b8a672ad57b21 /sbin/sysctl
parent17764ab6923baa8f86ff640f46bfadf216fabfcc (diff)
downloadsrc-a18f34fe7787ddda9447ae4be28d68c2f57a7031.tar.gz
src-a18f34fe7787ddda9447ae4be28d68c2f57a7031.zip
Don't request CTLTYPE_OPAQUE if we can't print them.
The intent is to skip expensive opaque sysctls like tcp_pcblist unless they are explicitly requested. Sysctl nodes like this don't show up in sysctl -a, but they do generate output that winds up being dropped, unless the user specifically requested binary/hex output or opaques. This reduces the runtime of sysctl in many circumstances on a loaded system. It also reduces the likelihood that simply gathering diagnostics on a sick machine (stuck lock, etc) via sysctl -a might push it over the edge into a total lockup. Reviewed by: jtl Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D11461
Notes
Notes: svn path=/head/; revision=321790
Diffstat (limited to 'sbin/sysctl')
-rw-r--r--sbin/sysctl/sysctl.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c
index 97ab6ad20602..51ae95809a11 100644
--- a/sbin/sysctl/sysctl.c
+++ b/sbin/sysctl/sysctl.c
@@ -925,6 +925,32 @@ show_var(int *oid, int nlen)
printf("%s", buf);
return (0);
}
+
+ /* don't fetch opaques that we don't know how to print */
+ if (ctltype == CTLTYPE_OPAQUE) {
+ if (strcmp(fmt, "S,clockinfo") == 0)
+ func = S_clockinfo;
+ else if (strcmp(fmt, "S,timeval") == 0)
+ func = S_timeval;
+ else if (strcmp(fmt, "S,loadavg") == 0)
+ func = S_loadavg;
+ else if (strcmp(fmt, "S,vmtotal") == 0)
+ func = S_vmtotal;
+#ifdef __amd64__
+ else if (strcmp(fmt, "S,efi_map_header") == 0)
+ func = S_efi_map;
+#endif
+#if defined(__amd64__) || defined(__i386__)
+ else if (strcmp(fmt, "S,bios_smap_xattr") == 0)
+ func = S_bios_smap_xattr;
+#endif
+ else {
+ func = NULL;
+ if (!bflag && !oflag && !xflag)
+ return (1);
+ }
+ }
+
/* find an estimate of how much we need for this var */
if (Bflag)
j = Bflag;
@@ -1045,24 +1071,6 @@ show_var(int *oid, int nlen)
case CTLTYPE_OPAQUE:
i = 0;
- if (strcmp(fmt, "S,clockinfo") == 0)
- func = S_clockinfo;
- else if (strcmp(fmt, "S,timeval") == 0)
- func = S_timeval;
- else if (strcmp(fmt, "S,loadavg") == 0)
- func = S_loadavg;
- else if (strcmp(fmt, "S,vmtotal") == 0)
- func = S_vmtotal;
-#ifdef __amd64__
- else if (strcmp(fmt, "S,efi_map_header") == 0)
- func = S_efi_map;
-#endif
-#if defined(__amd64__) || defined(__i386__)
- else if (strcmp(fmt, "S,bios_smap_xattr") == 0)
- func = S_bios_smap_xattr;
-#endif
- else
- func = NULL;
if (func) {
if (!nflag)
printf("%s%s", name, sep);