Commit Graph

105 Commits

Author SHA1 Message Date
Xin LI
6f36135181 Use the right format string for line buffer.
PR:		bin/174910
Submitted by:	Fabian Keil <fk fabiankeil.de>
2013-01-13 04:28:44 +00:00
Xin LI
da178c777f Teach sysctl(8) about parsing a file (while I'm there also give it
capability of parsing both = and : formats).

Submitted by:	hrs (initial version, bugs are mine)
MFC after:	3 months
2012-12-13 23:32:47 +00:00
Alfred Perlstein
403c7f59d5 Make Tflag and Wflag filters work for more sysctl options.
To do this move the Tflag and Wflag checks earlier in show_var() so
we bail earlier for variables not matching our query.
2012-12-12 02:55:40 +00:00
Alfred Perlstein
9ecd2e32cd Allow sysctl to filter boot and runtime tunables.
Add the following flags to sysctl:
 -W  - show only writable sysctls
 -T  - show only tuneable sysctls

This can be used to create a /var/run/sysctl.boot to
compare set tunables versus booted tunables.

Sponsored by: iXsystems
2012-12-11 01:28:06 +00:00
Xin LI
aae7510122 In parse():
- Only operate on copy, don't operate on source.
 - Eliminate home-rolled strsep().
 - Constify the parameter.

MFC after:	2 weeks
2012-12-11 01:12:29 +00:00
Eitan Adler
ad0e6cda92 s/Free Memory Pages/Free Memory/ to avoid confusion, since we're
reporting a number of bytes rather than a number of pages

PR:		misc/165208
Submitted by:	Arnaud Lacombe <lacombar@gmail.com>
Approved by:	cperciva
MFC after:	3 days
2012-04-11 14:18:18 +00:00
John Baldwin
0b6230f135 If the -d flag is specified, ignore any new values specified and only
display the descriptions of specified nodes.

Reported by:	Jason Hellenthal  jhell of dataix net
MFC after:	2 weeks
2011-12-01 15:01:23 +00:00
Matthew D Fleming
cbc134ad03 Introduce signed and unsigned version of CTLTYPE_QUAD, renaming
existing uses.  Rename sysctl_handle_quad() to sysctl_handle_64().
2011-01-19 23:00:25 +00:00
Matthew D Fleming
f8e4b4ef49 sysctl(8) should use the CTLTYPE to determine the type of data when
reading.  (This was already done for writing to a sysctl).  This
requires all SYSCTL setups to specify a type.  Most of them are now
checked at compile-time.

Remove SYSCTL_*X* sysctl additions as the print being in hex should be
controlled by the -x flag to sysctl(8).

Succested by:	bde
2011-01-19 17:04:07 +00:00
Matthew D Fleming
5bf6a94016 The kernel is not exporting any "T,dev_t" sysctl nodes anymore, so
remove the capability and mention from sysctl(8).
2011-01-17 23:36:53 +00:00
Marko Zec
13e86ef7ee Make the format of "Real Memory" and "Virtual Memory" lines more
consistent with the rest of sysctl vm.vmtotal output.

MFC after:	3 days
2010-09-16 10:53:01 +00:00
Rebecca Cran
f2359a2473 Free the memory allocated via strdup.
PR:		bin/113881
Submitted by:	Alexander Drozdov  dzal_mail mtu-net.ru
Approved by:	rrs (mentor)
MFC after:	1 week
2010-03-13 11:08:57 +00:00
Ulrich Spörlein
6d7a8f6cba sysctl(8): make WARNS=3 clean
Fixes inspired by work done in DragonflyBSD.

PR:		bin/140016
Approved by:	ed (Co-mentor)
2010-02-15 14:08:06 +00:00
Gavin Atkinson
aea5fda5dc Add -i to usage()
Noticed by:	ru
MFC after:	5 days
2010-02-09 19:13:45 +00:00
Gavin Atkinson
24b2aa3259 Implement the "-i" option to sysctl(8), to ignore failures while
retrieving individual OIDs.  This allows the same list of OIDs to be
passed to sysctl(8) across different systems where particular OIDs may not
exist, and still get as much information as possible from them.

PR:		bin/123644
Submitted by:	dhw
Approved by:	ed (mentor)
MFC after:	2 weeks
2010-01-31 19:33:25 +00:00
Ed Schouten
8f1c21a6e3 Just use devname(3) to print device names.
Right now sysctl just prints the major/minor numbers of a device.
Instead of rolling our own routine for this, we'd better just call
devname(3) to perform a translation to a device name for us.
2009-11-03 11:41:21 +00:00
Ed Schouten
a7b5ad271c Make input parsing in Farhenheit actually work.
Don't clobber *p with '\0' when testing whether it has the value of 'F'.
Just use the semantics of strtof() properly. If it returns p, we know
that it parsed the string until it reached 'C' or 'F'.

The code has not changed since it has been imported (r161951, Sep 3,
2006).

Submitted by:	Alexandre Perrin <kaworu@kaworu.ch>
MFC after:	1 week
2009-10-21 18:31:54 +00:00
John Hay
db87e2dc03 time_t does not always fit into long, for instance on arm. So rather cast
it intmax_t and use %j in printf.
2009-06-23 06:46:14 +00:00
Mike Makonnen
d9fcd86c3a The sysctl(8) program exits on some errors and only emits warnings on
others. In the case where it displayed warnings it would still return
succesfully. Modify it so that it returns the number of sysctls that
it was not able to set.

Make use of this in rc.d to display only *unsuccessfull* attempts to
set sysctls.
2008-06-23 22:06:28 +00:00
Alexander Leidinger
9f05d312b3 Backout sensors framework.
Requested by:	phk
Discussed on:	cvs-all
2007-10-15 20:00:24 +00:00
Alexander Leidinger
99f6b270e3 Import OpenBSD's sysctl hardware sensors framework.
This commit includes the following core components:

 * sample configuration file for sensorsd
 * rc(8) script and glue code for sensorsd(8)
 * sysctl(3) doc fixes for CTL_HW tree
 * sysctl(3) documentation for hardware sensors
 * sysctl(8) documentation for hardware sensors
 * support for the sensor structure for sysctl(8)
 * rc.conf(5) documentation for starting sensorsd(8)
 * sensor_attach(9) et al documentation
 * /sys/kern/kern_sensors.c
   o sensor_attach(9) API for drivers to register ksensors
   o sensor_task_register(9) API for the update task
   o sysctl(3) glue code
   o hw.sensors shadow tree for sysctl(8) internal magic
 * <sys/sensors.h>
 * HW_SENSORS definition for <sys/sysctl.h>
 * sensors display for systat(1), including documentation
 * sensorsd(8) and all applicable documentation

The userland part of the framework is entirely source-code
compatible with OpenBSD 4.1, 4.2 and  -current as of today.

All sensor readings can be viewed with `sysctl hw.sensors`,
monitored in semi-realtime with `systat -sensors` and also
logged with `sensorsd`.

Submitted by:	Constantine A. Murenin <cnst@FreeBSD.org>
Sponsored by:	Google Summer of Code 2007 (GSoC2007/cnst-sensors)
Mentored by:	syrinx
Tested by:	many
OKed by:	kensmith
Obtained from:	OpenBSD (parts)
2007-10-14 10:45:31 +00:00
Bruce Evans
6b6b665bfd When we return from a "show" function without printing anything except
a warning, return 1 instead of 0 to indicate that we didn't print
anything, so that top-level callers don't print a spurious newline.
This is mainly to fix output formatting when stderr is redirected.  It
also helps in some cases when stderr is interleaved with stdout,
depending on the details of the interleaving (this program has the
usual null explicit support for syncing stderr with stdout).

Return 1 instead of -1 after printing the "malloc failed" warning, since
the return value is boolean.
2007-06-11 13:02:15 +00:00
David Malone
e37d2b3001 Some improvements to the int-type printing code based on suggestions by bde. 2007-06-10 20:11:52 +00:00
David Malone
fd8c668afc Fix a number of WARNS, including printf, constness and unsigned comparison
warnings.
2007-06-10 19:32:20 +00:00
David Malone
21e1f59618 Some style improvements suggested by bde, including removing an
unused include, adding parens for return and sizeof and renaming,
adding some missing whitespace and sorting some variables.
2007-06-10 19:13:40 +00:00
David Malone
41e419cb61 Use common code for printing ints and longs by coppying the sysctl
value into a variable of the right type and then printing it via
an intmax_t. This makes avoids some duplication and makes it easy
to add a new integer format Q for printing things of type CTLTYPE_QUAD.
2007-06-04 18:02:23 +00:00
Warner Losh
f195a1221f Style: Shorten a couple of lines with u_int and u_long. 2006-12-10 06:36:41 +00:00
Ruslan Ermilov
bad4d172b4 - Revert signedness type changes to "struct vmtotal"; by making
them unsigned I made the possible overflows hard to detect,
  and it only saved 1 bit which isn't principal, even less now
  that the underlying issue with the total of virtual memory has
  been fixed.  (For the record, it will overflow with >=2T of
  VM total, with 32-bit ints used to keep counters in pages.)

- While here, fix printing of other "struct vmtotal" members
  such as t_rq, t_dw, t_pw, and t_sw as they are also signed.

Reviewed by:	bde
MFC after:	3 days
2006-11-28 12:46:02 +00:00
Ruslan Ermilov
20739dfa44 Fix the format specifier suitable for uintmax_t. 2006-11-23 11:51:23 +00:00
Ruslan Ermilov
5c88a11e6e - Fix types of "struct vmmeter" members so they are unsigned.
- Fix overflow bugs in sysctl(8), systat(1), and vmstat(8)
  when printing values of "struct vmmeter" in kilobytes as
  they don't necessarily fit into 32 bits.  (Fix sysctl(8)
  reporting of a total virtual memory; it's in pages too.)
2006-11-20 16:04:41 +00:00
Hartmut Brandt
d566310d21 Remove a debugging statement from the previous commit. 2006-10-12 15:44:51 +00:00
Hartmut Brandt
48cd487aae Don't free the buffer with the sysctl value before printing it. 2006-10-12 15:31:23 +00:00
Ruslan Ermilov
ccf2597759 While convenient, avoid using alloca() for reasons specified in
the BUGS section of the alloca(3) manpage.  In particular, when
the number of TCP sockets is several tens of thousand, trying to
"sysctl -a" would SIGSEGV on the net.inet.tcp.pcblist entry (it
would exceed the stacksize ulimit, in an undetectable manner).

Reported by:	Igor Sysoev
2006-09-06 20:15:43 +00:00
Hajimu UMEMOTO
d45564dcfe Support Celsius (nn.nC), Fahrenheit (nn.nF) and Kelvin (nnnn) to
specify temperature.

Reviewed by:	njl
MFC after:	3 days
2006-09-03 15:10:04 +00:00
Ruslan Ermilov
e556ec911a Fix printing of integer Kelvins broken in rev. 1.71, which is
fatal on sizeof(int) != sizeof(long) systems (such as amd64).

MFC after:	1 day
2006-08-15 13:32:39 +00:00
David E. O'Brien
c157a036a9 Add an extension to the UINT & ULONG types. The XINT & XLONG types behave
the same, except sysctl(8) will print out the values in hex.
2006-08-12 23:33:10 +00:00
Nate Lawson
091eb5a3db Use floating point instead of hacking something together. Suggested by
bde@.  Fix nearby int conversion and a couple style bugs.

MFC after:	1 day
2006-08-04 07:31:55 +00:00
Nate Lawson
e05cdb7490 Fix printing of negative decimal values in Kelvin to Celsius conversion.
MFC after:	3 days
2006-07-25 02:28:43 +00:00
Ruslan Ermilov
855b068a9a Add -q to usage(). 2005-12-01 21:59:24 +00:00
Robert Watson
f93d36fd92 Add "-q" argument to sysctl(8), which suppresses a limited set of warnings/
errors generated.  In particular, it suppresses "unknown oid" when
attempting to get or set a sysctl not present in the kernel.

MFC after:	1 week
2005-09-15 16:08:04 +00:00
Matthew N. Dodd
b2680e2048 Show descriptions for type CTLTYPE_NODES. 2005-04-13 06:59:07 +00:00
Matthew N. Dodd
9f98e452c3 Zero buffers. Seatbelt against sysctl(3) returning non-NUL terminated
string data.
2005-04-13 06:56:31 +00:00
Ruslan Ermilov
8d646af581 Sync program's usage() with manpage's SYNOPSIS. 2005-02-10 09:19:34 +00:00
Suleiman Souhlal
1d4961c06f Get rid of a NULL dereference when oid is too long.
Reviewed by:	keramida
Approved by:	grehan (mentor)
MFC after:	1 week
2005-01-25 14:37:43 +00:00
Lukas Ertl
0a16dedc07 Use correct format string.
Submitted by:   ssouhlal
2004-09-17 17:08:44 +00:00
Peter Wemm
c591d41f7c Add a suffix descriptor for the acpi thermal values as a hint for the userland
sysctl tool to print a more readable value for temperatures.
2004-08-30 22:42:10 +00:00
Mark Murray
4c723140a4 Remove advertising clause from University of California Regent's license,
per letter dated July 22, 1999.

Approved by: core, imp
2004-04-09 19:58:40 +00:00
Dima Dorfman
4d90830fd8 Add CTLTYPE_QUAD to the list of types for which we don't want an empty
value.  All the other numeric types are doing it . . .
2004-03-02 05:42:52 +00:00
Dag-Erling Smørgrav
705916c692 Whitespace cleanup. 2003-11-07 16:41:47 +00:00
Dag-Erling Smørgrav
45817aaa9c Add a command-line option to format output for human readability.
Currently, the only effect it has is to print some (but not all) numbers
using thousands separators.
2003-11-07 16:33:45 +00:00