Commit Graph

140 Commits

Author SHA1 Message Date
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
Mike Silbersack
ac8711d28e Fix a few style glitches in the previous commit and make the
tunable error message more brief.

Suggested by:	bde
2003-11-01 07:06:04 +00:00
Peter Wemm
7e9c84c757 Fix a 64 bit warning. Have set_T_dev_t() take a pointer to a size_t rather
than a pointer to an int, since that is what it really wants anyway.
2003-10-26 04:45:08 +00:00
Mike Silbersack
d108e6633b Wrap a long line in the previous commit
Suggested by:	njl
2003-10-21 18:48:49 +00:00
Mike Silbersack
9b4b73b7ba Have sysctl print out a more useful error message when it detects that the
user has attempted to write to a read only, tunable value.
2003-10-21 16:49:30 +00:00
Robert Watson
a78d3eaffc Tighten up the string->integer conversion in sysctl(8):
(1) Reject zero-length strings for CTLTYPE_INT, _UINT, _LONG,
    _ULONG.  Do not silently convert to 0.

(2) When converting CTLTYPE_INT, _UINT, _LONG, and _ULONG, check the
    end pointer generated by strtol() and strtoul() rather than
    discarding it.  Reject the string if either none of the string
    was useful for conversion to an integer, or if there was
    trailing garbage.

I.e., we will not allow you to set a numeric sysctl to a value unless
we can completely convert the string argument to a numeric value.
I tripped over this when I put the following in /etc/sysctl.conf:

   kern.maxfiles="4000"

Ouch.
2003-06-15 06:26:08 +00:00
Poul-Henning Kamp
5b03e4b6a1 Output machdep.guessed_bootdev as an integer rather than try to format
it according to ancient and obsolete rules.

This removes one more user of <sys/diskslice.h>
2003-04-03 21:41:14 +00:00
Peter Wemm
661b2c1683 Fix what I think is an off-by-one in certain worst-case scenarios
caused by rev 1.45.  (eg: the estimate being exactly half of the result.)
2003-01-22 00:34:22 +00:00
Matthew Dillon
654e22e7bb Cleanup the formatting from the last commit, convert everything to
a more human-readable 'kilobytes' instead of pages.
2003-01-11 20:03:43 +00:00
Matthew Dillon
f7550ecf3f Make 'sysctl vm.vmtotal' work properly using updated patch from Hiten.
(the patch in the PR was stale).

PR:             kern/5689
Submitted by:   Hiten Pandya <hiten@unixdaemons.com>
2003-01-11 07:29:47 +00:00
Peter Wemm
9866352ec7 Fix a "bug" in sysctl(8). Limit the length when we print a string from
the kernel rather than ignoring the length and keeping on going till we
finally hit a \0 character in the buffer.
2002-11-12 21:18:21 +00:00
Philippe Charnier
7fed38d0a0 Replace various spelling with FALLTHROUGH which is lint()able 2002-08-25 13:10:45 +00:00
Alfred Perlstein
996076bbc7 Don't err(3) (and exit prematurely) when a sysctl's object size has
changed, instead just warn(3)
2002-05-24 08:34:18 +00:00
Andrey A. Chernov
76d3dc5297 Don't forget to null-terminate string we got from sysctl (f.e. in 'A' format).
Stack garbadge may be printed otherwise.
2002-05-08 23:49:19 +00:00
Poul-Henning Kamp
b35c8f287d Take the "tickadj" element out of struct clockinfo. Our adjtime(2)
implementation is being changed and the very concept of tickadj will
no longer be meaningful.
2002-04-15 12:11:06 +00:00
Luigi Rizzo
bca9bbeae7 Make the handling of machdep.guessed_bootdev compiled on i386 only. 2002-03-11 06:50:28 +00:00
Luigi Rizzo
60cf2c1254 Export a (machine dependent) kernel variable bootdev as
machdep.guessed_bootdev, and add code to sysctl to parse its value
and give a (not necessarily correct) name to the device we booted
from (the main motivation for this code is to use the info in the
PicoBSD boot scripts, and the impact on the kernel is minimal).

NOTE: the information available in bootdev is not always reliable,
so you should not trust it too much.  The parsing code is the same
as in boot2.c, and cannot cover all cases -- as it is, it seems to
work fine with floppies and IDE disks recognised by the BIOS. It
_should_ work as well with SCSI disks recognised by the BIOS.
Booting from a CDROM in floppy emulation will return /dev/fd0 (because
this is what the BIOS tells us).
Booting off the network (e.g. with etherboot) leaves bootdev unset so
the value will be printed as "invalid (0xffffffff)".

Finally, this feature might go away at some point, hopefully when we
have a more reliable way to get the same information.

MFC-after: 5 days
2002-03-10 20:08:44 +00:00
Bruce Evans
ce68584226 #include <sys/time.h> instead of depending on namespace pollution in
<sys/stat.h> for its prerequisite <sys/time.h>.

#include <sys/param.h> in the correct place instead of bogusly including
<sys/types.h>.
2002-02-25 03:36:06 +00:00
Poul-Henning Kamp
d58f005463 Allow setting of variables of type dev_t by indicating the name of
a special file on the command line, eg:
  sysctl kern.dumpdev=/dev/ad1s1b

In parse(), when a value is given for a CTLTYPE_QUAD variable,
newval and newsize erroneously fail to be set because of an early
"break".

show_var() contains code that duplicates the functionality of the
oidfmt() function.

PR:		33151, 33150
Submitted by:	Thomas Quinot <thomas@cuivre.fr.eu.org>
2001-12-30 10:33:34 +00:00
Luigi Rizzo
6105f81565 Add code to export and print the description associated to sysctl
variables. Use the -d flag in sysctl(8) to see this information.

Possible extensions to sysctl:
 + report variables that do not have a description
 + given a name, report the oid it maps to.

Note to developers: have a look at your code, there are a number of
	variables which do not have a description.

Note to developers: do we want this in 4.5 ? It is a very small change
	and very useful for documentation purposes.

Suggested by: Orion Hodson
2001-12-16 02:55:41 +00:00
Anton Berezin
d0b8aabb19 Implement -e option. It modifies the output produced by sysctl(8) in
such a way that the name and the value of the variable(s) are separated
with `=' instead of the usual `: '.  This is useful for producing output
that can be fed back to the sysctl utility (pasted to sysctl.conf, for
example).

Reviewed by:	rwatson
Approved by:	markm
MFC after:	2 weeks
2001-10-30 20:15:32 +00:00
Jim Pirzyk
1ce1a53dc3 modfied sysctl command to allow setting values > 2GB if the mib supports it.
PR:		kern/21132
Reviewed by:	no objections to by -arch
MFC after:	1 month
2001-06-18 21:06:24 +00:00
Dima Dorfman
31fb466194 Normalize the use of sizeof according to style(9).
Reviewed by:	md5(1)
2001-06-09 03:56:16 +00:00
Dima Dorfman
ce35978374 Remove unused variable (descr) in show_var().
PR:		22582
Submitted by:	Giorgos Keramidas <charon@gray.westgate.gr>
2001-06-01 02:58:09 +00:00
Dag-Erling Smørgrav
a89ab9bbe4 Perform random drive-by style cleanups, and rewrite a while loop that
offended my artistic sensibilities.
2001-05-28 12:35:40 +00:00
Dag-Erling Smørgrav
9a2402bc41 Try to make sysctl options slightly more orthogonal:
- introduce a -o option that displays opaque variables.
 - introduce a -x option that displays opaque variables in full.
 - deprecate -A in favor of -ao and -X in favor of -ax.
 - remove -A and -X from usage() and SYNOPSIS (but not from DESCRIPTION).
 - ignore -a if one or more variables were listed on the command line.
 - deprecate -w, it is not needed to determine the user's intentions.
 - some language and style cleanup in the man page.

This commit should not break any existing scripts.

MFC after:	4 weeks
2001-05-28 12:15:45 +00:00
Dag-Erling Smørgrav
0ef56fd857 Document the -N option in the usage message and the man page. 2001-01-14 19:08:58 +00:00
Dag-Erling Smørgrav
ca5fac557f Add a -N option that makes sysctl(8) print out just the variable names.
Zsh users can add the following to their .zshrc for sysctl completion:

function listsysctls {
    case $1 in
    *.*) set -A reply $(sysctl -AN ${1%.*}) ;;
    *) set -A reply $(sysctl -AN) ;;
    esac
}
compctl -K listsysctls sysctl

While I'm here, brucify the getopt() switch.
2001-01-14 16:40:06 +00:00
Andrew Gallatin
3c884b5097 Give correct results for SYSCTL_LONG arrays when sizeof(int) != sizeof(long)
This fixes unaligned access on alpha for, eg, sysctl kern.ipc.mbtypes.
2000-10-23 21:04:18 +00:00
Poul-Henning Kamp
aa02fb5729 Array of long support.
Submitted by:	Ian Dowse <iedowse@maths.tcd.ie>
2000-07-11 21:59:54 +00:00
John Baldwin
9701cd40b4 Support for unsigned integer and long sysctl variables. Update the
SYSCTL_LONG macro to be consistent with other integer sysctl variables
and require an initial value instead of assuming 0.  Update several
sysctl variables to use the unsigned types.

PR:		15251
Submitted by:	Kelly Yancey <kbyanc@posi.net>
2000-07-05 07:46:41 +00:00
Poul-Henning Kamp
6ed3a29777 Handle minors like ls(1) does it.
PR:		19179
Submitted by:	Kelly Yancey <kbyanc@posi.net>
2000-06-10 19:55:39 +00:00
Dag-Erling Smørgrav
2d730c265e Belatedly back out rev. 1.20. 1999-11-22 08:38:29 +00:00
Greg Lehey
26909c8019 Allow octal or hex input.
Suggested-by:	Geoff Steckel <gwes@sitaranetworks.com>
1999-11-17 23:42:09 +00:00
Peter Wemm
7f3dea244c $Id$ -> $FreeBSD$ 1999-08-28 00:22:10 +00:00
Bill Fumerola
c1160fe492 Avoid ambigious if/else 1999-07-21 02:49:42 +00:00
Dag-Erling Smørgrav
81e7454a25 Clean up option handling a little.
Add an option for showing sysctl descriptions instead of their values.
1999-01-10 02:10:08 +00:00
Poul-Henning Kamp
2b4c0a3bc6 Allow for printing out integer arrays. 1998-11-08 19:27:43 +00:00
Doug Rabson
dbf9b92f80 Change length arguments to sysctl to size_t. 1998-08-25 07:38:19 +00:00
Bruce Evans
c2deb6082e Don't assume that time_t is long. 1998-06-29 17:54:29 +00:00
John Polstra
14b94d0464 Add missing argument detected by "-Wformat". 1997-11-18 03:37:45 +00:00
Philippe Charnier
d9b1bc7779 Use err(3). Change err(-1,... to err(1,... 1997-10-20 12:53:54 +00:00
John Hay
0fad62aead Display tickadj in struct clockinfo. 1997-06-24 18:23:32 +00:00
Warner Losh
6c3f552a31 compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.
1997-03-31 05:11:47 +00:00
Peter Wemm
476602a9d0 Revert $FreeBSD$ to $Id$ 1997-02-22 16:15:28 +00:00
Jordan K. Hubbard
1130b656e5 Make the long-awaited change from $Id$ to $FreeBSD$
This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore.  This update would have been
insane otherwise.
1997-01-14 07:20:47 +00:00
Sujal Patel
019d933039 Fix a core dump when the user gives "-w" without an "=" 1996-04-10 00:53:22 +00:00
Poul-Henning Kamp
1d86b91c32 The rewamped sysctl program that will find all the variables itself.
Also a couple of handy new options.
1995-12-21 12:39:25 +00:00
Poul-Henning Kamp
07f16e5324 Make sysctl compile again by removing all the debug stuff. 1995-11-17 16:28:42 +00:00
Rodney W. Grimes
d3628763db Merge RELENG_2_0_5 into HEAD 1995-06-11 19:33:05 +00:00
Rodney W. Grimes
709e8f9ae1 Remove trailing whitespace. 1995-05-30 03:57:47 +00:00
Garrett Wollman
55678a2eb9 Learn how to print out kern.dumpdev as a name. 1995-05-12 19:10:56 +00:00
Garrett Wollman
9426bb7c1d Allow the user access to net.inet.igmp, even though there's nothing
sysctl(8) can interpret there.  (Someday there might be.)
1995-02-16 00:28:42 +00:00
Garrett Wollman
35c13fa033 Implement TCP MIB variables. 1995-02-09 23:16:17 +00:00
Garrett Wollman
ebe06549fd Suppress irritating extra newline after kern.boottime. 1994-08-08 15:37:35 +00:00
Rodney W. Grimes
dea673e932 BSD 4.4 Lite usr.sbin Sources 1994-05-26 05:23:31 +00:00