Imported envsys 2, a brief description of the new features:
(Part 3: userland) * Support for detachable sensors. * Cleaned up the API for simplicity and efficiency. * Ability to send capacity/critical/warning events to powerd(8). * Adapted all the code to the new locking order. * Compatibility with the old envsys API: the ENVSYS_GTREINFO and ENVSYS_GTREDATA ioctl(2)s are supported. * Added support for a 'dictionary based communication channel' between sysmon_power(9) and powerd(8), that means there is no 32 bytes event size restriction anymore. * Binary compatibility with old envstat(8) and powerd(8) via COMPAT_40. * All drivers with the n^2 gtredata bug were fixed, PR kern/36226. Tested by: blymn: smsc(4). bouyer: ipmi(4), mfi(4). kefren: ug(4). njoly: viaenv(4), adt7463.c. riz: owtemp(4). xtraeme: acpiacad(4), acpibat(4), acpitz(4), aiboost(4), it(4), lm(4).
This commit is contained in:
parent
da3f163bd2
commit
af211bb4e3
|
@ -1,7 +1,11 @@
|
||||||
# $NetBSD: Makefile,v 1.1 2000/03/10 05:51:57 groo Exp $
|
# $NetBSD: Makefile,v 1.2 2007/07/01 07:39:45 xtraeme Exp $
|
||||||
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
|
||||||
|
|
||||||
PROG= envstat
|
PROG= envstat
|
||||||
MAN= envstat.8
|
|
||||||
|
LDADD= -lprop
|
||||||
|
DPADD= ${LIBPROP}
|
||||||
|
|
||||||
|
MAN= ${PROG}.8
|
||||||
|
WARNS= 4
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
.include <bsd.prog.mk>
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
.\" $NetBSD: envstat.8,v 1.15 2007/05/07 11:01:28 xtraeme Exp $
|
.\" $NetBSD: envstat.8,v 1.16 2007/07/01 07:39:46 xtraeme Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 2000 The NetBSD Foundation, Inc.
|
.\" Copyright (c) 2000, 2007 The NetBSD Foundation, Inc.
|
||||||
.\" All rights reserved.
|
.\" All rights reserved.
|
||||||
.\"
|
.\"
|
||||||
.\" This code is derived from software contributed to The NetBSD Foundation
|
.\" This code is derived from software contributed to The NetBSD Foundation
|
||||||
.\" by Bill Squier.
|
.\" by Juan Romero Pardines and Bill Squier.
|
||||||
.\"
|
.\"
|
||||||
.\" Redistribution and use in source and binary forms, with or without
|
.\" Redistribution and use in source and binary forms, with or without
|
||||||
.\" modification, are permitted provided that the following conditions
|
.\" modification, are permitted provided that the following conditions
|
||||||
|
@ -34,40 +34,52 @@
|
||||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd May 7, 2007
|
.Dd June 15, 2007
|
||||||
.Dt ENVSTAT 8
|
.Dt ENVSTAT 8
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm envstat
|
.Nm envstat
|
||||||
.Nd display environmental sensor readings
|
.Nd utility to handle environmental sensors
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl flr
|
.Op Fl Dflx
|
||||||
|
.Op Fl d Ar device
|
||||||
.Op Fl i Ar interval
|
.Op Fl i Ar interval
|
||||||
.Op Fl n Ar headrep
|
.Op Fl m Ar critical=... critmax=... critmin=... desc=... rfact=...
|
||||||
.Op Fl s Ar sensor1,sensor2,...
|
.Op Fl s Ar sensor1,sensor2,...
|
||||||
.Op Fl w Ar width
|
.Op Fl w Ar width
|
||||||
.Op Ar device
|
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
displays sensor readings from any device which supports the
|
is a utility that handles various aspects of the sensors
|
||||||
|
registered with the
|
||||||
.Xr envsys 4
|
.Xr envsys 4
|
||||||
API.
|
framework.
|
||||||
Readings are displayed in columns, one column per sensor.
|
It is capable of displaying sensor values as well as
|
||||||
Column widths as well as displayed sensors are fully customizable.
|
changing parameters and setting critical limits for the sensors.
|
||||||
The column headers display the name (stored in the device driver) as
|
|
||||||
well as the units of each sensor.
|
|
||||||
.Pp
|
.Pp
|
||||||
The options are as follows:
|
In display mode, column widths as well as displayed sensors
|
||||||
|
are fully customizable.
|
||||||
|
Critical limits can be set in a per-sensor basis.
|
||||||
|
If critical limits were set previously, the display mode will show
|
||||||
|
the critical limits in addition to the current values.
|
||||||
|
.Pp
|
||||||
|
The following options are available:
|
||||||
.Bl -tag -width flag
|
.Bl -tag -width flag
|
||||||
|
.It Fl D
|
||||||
|
Display the names of the drivers that were registered with
|
||||||
|
the
|
||||||
|
.Xr envsys 4
|
||||||
|
framework, one per line.
|
||||||
|
.It Fl d
|
||||||
|
Display only the sensors for a given
|
||||||
|
.Ar driver .
|
||||||
|
This is useful when there are multiple drivers registered and
|
||||||
|
you want to only see those from a specific driver.
|
||||||
.It Fl f
|
.It Fl f
|
||||||
Display any temperature values in degrees Fahrenheit.
|
Display temperature values in degrees Fahrenheit.
|
||||||
The default is to display temperature values in degrees Celsius.
|
The default is to display temperature values in degrees Celsius.
|
||||||
.It Fl l
|
When changing properties on a sensor and this flag is specified,
|
||||||
List the names of all supported sensors, one per line.
|
the value provided must be in degress Fahrenheit too.
|
||||||
Use of this flag causes
|
|
||||||
.Nm
|
|
||||||
to ignore all other option flags.
|
|
||||||
.It Fl i
|
.It Fl i
|
||||||
Repeat the display every
|
Repeat the display every
|
||||||
.Ar interval
|
.Ar interval
|
||||||
|
@ -78,17 +90,23 @@ See the individual device's manual page for meaningful values for
|
||||||
If not specified, or specified as 0,
|
If not specified, or specified as 0,
|
||||||
.Nm
|
.Nm
|
||||||
produces one line of values and exits.
|
produces one line of values and exits.
|
||||||
.It Fl n
|
.It Fl l
|
||||||
Display a new header every
|
List the names of all supported sensors, one per line.
|
||||||
.Ar headrep
|
Use of this flag causes
|
||||||
lines.
|
.Nm
|
||||||
An argument of 0 disables header line printing completely.
|
to ignore all other option flags.
|
||||||
The default is every 22 lines.
|
.It Fl m
|
||||||
.It Fl r
|
This flag can be used to change a description of a sensor, to
|
||||||
Display the sensors row wise.
|
change the rfact (resistor factor) in a voltage sensor or
|
||||||
This is useful when the number of sensors is large.
|
to set critical capacity for (battery sensors) and critical
|
||||||
This option also displays fractional values when present
|
min and max limits (for all supported sensors).
|
||||||
(e.g., the percentage battery charge).
|
Recognized keywords are:
|
||||||
|
.Ar critical , critmax , critmin , desc ,
|
||||||
|
and
|
||||||
|
.Ar rfact .
|
||||||
|
See the
|
||||||
|
.Sx EXAMPLES
|
||||||
|
section for more information.
|
||||||
.It Fl s
|
.It Fl s
|
||||||
Restrict the display to the named sensors.
|
Restrict the display to the named sensors.
|
||||||
The sensor names must be supplied as a comma separated list.
|
The sensor names must be supplied as a comma separated list.
|
||||||
|
@ -98,15 +116,218 @@ Use
|
||||||
.Ar width
|
.Ar width
|
||||||
as the column width for the output.
|
as the column width for the output.
|
||||||
Each column is additionally separated by a single space.
|
Each column is additionally separated by a single space.
|
||||||
The default is either the length of the longest sensor
|
The default is the length of the longest sensor name.
|
||||||
name or spread evenly to fill 80 columns, whichever is greater.
|
.It Fl x
|
||||||
|
Shows the property list used by the
|
||||||
|
.Xr sysmon_envsys 9
|
||||||
|
framework that contains details about all registered drivers
|
||||||
|
and sensors.
|
||||||
.El
|
.El
|
||||||
|
.Ss CRITICAL LIMITS
|
||||||
|
Starting with
|
||||||
|
.Tn envsys 2 ,
|
||||||
|
it is possible to set critical limits on a specified sensor.
|
||||||
|
Only one critical limit can be set at a time for a sensor.
|
||||||
|
For example, you cannot assign multiple limits for the same
|
||||||
|
sensor or for different sensors.
|
||||||
|
.Pp
|
||||||
|
There are three types of
|
||||||
|
critical limits:
|
||||||
|
.Ar capacity ,
|
||||||
|
.Ar max ,
|
||||||
|
and
|
||||||
|
.Ar min .
|
||||||
|
When one of them is set and sensor's current value reaches
|
||||||
|
it, an event will be sent to
|
||||||
|
.Xr powerd 8 .
|
||||||
|
.Pp
|
||||||
|
Three arguments are required to set/remove a critical/capacity limit,
|
||||||
|
to change a description or to change the rfact:
|
||||||
|
.Pp
|
||||||
|
.Bl -item -offset indent -compact
|
||||||
|
.It
|
||||||
|
.Fl d
|
||||||
|
is required to specify the device that is handling
|
||||||
|
the sensor.
|
||||||
|
.It
|
||||||
|
.Fl m
|
||||||
|
is required to set the new target mode.
|
||||||
|
.It
|
||||||
|
.Fl s
|
||||||
|
is required to specify sensor's name.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The available targets for the
|
||||||
|
.Fl m
|
||||||
|
flag are:
|
||||||
|
.Pp
|
||||||
|
.Bl -bullet -compact -offset indent
|
||||||
|
.It
|
||||||
|
.Ar critical
|
||||||
|
accepts a percentage number for battery sensors (those showing
|
||||||
|
a percentage in display mode), also the
|
||||||
|
.Sy remove
|
||||||
|
keyword can be used to remove the limit.
|
||||||
|
.It
|
||||||
|
.Ar critmax
|
||||||
|
accepts a number that will be used for the max critical limit
|
||||||
|
or accepts the
|
||||||
|
.Sy remove
|
||||||
|
keyword.
|
||||||
|
.It
|
||||||
|
.Ar critmin
|
||||||
|
accepts a number that will be used for the min critical limit
|
||||||
|
or accepts the
|
||||||
|
.Sy remove
|
||||||
|
keyword.
|
||||||
|
.It
|
||||||
|
.Ar desc
|
||||||
|
accepts a new string that will be used as new description.
|
||||||
|
.It
|
||||||
|
.Ar rfact
|
||||||
|
accepts a number that will be used as new rfact in voltage sensors.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
Also is possible to remove a critical limit if one was set before,
|
||||||
|
with the
|
||||||
|
.Ar remove
|
||||||
|
keyword passed to the
|
||||||
|
.Ar critical ,
|
||||||
|
.Ar critmax ,
|
||||||
|
or
|
||||||
|
.Ar critmin
|
||||||
|
target.
|
||||||
|
See the
|
||||||
|
.Sx EXAMPLES
|
||||||
|
for information how to use it.
|
||||||
|
.Pp
|
||||||
|
.Ss CONFIGURATION FILE
|
||||||
|
It's possible to change properties with the
|
||||||
|
.Pa /etc/envsys.conf
|
||||||
|
configuration file. The syntax for this file is the following:
|
||||||
|
.Bd -literal
|
||||||
|
device:sensor name:target:value
|
||||||
|
|
||||||
|
aiboost0:CPU Temperature:critmax:70
|
||||||
|
lm0:Temp0:desc:CPU Temperature
|
||||||
|
smsc0:+3.3V:rfact:56000
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
In the example configuration file the first argument is the name of
|
||||||
|
the device, second argument is the name of the sensor that we want to change,
|
||||||
|
third argument is the target that will be used for the
|
||||||
|
.Ar -m
|
||||||
|
flag and finally the four arguments in the value that will be used for the
|
||||||
|
target.
|
||||||
|
.Pp
|
||||||
|
The first example sets a critical over limit of
|
||||||
|
.Dq 70
|
||||||
|
degC to the
|
||||||
|
.Dq CPU Temperature
|
||||||
|
sensor in the
|
||||||
|
.Dq aiboost0
|
||||||
|
device. By default the value specified on temperature sensors must be
|
||||||
|
in degrees Celsius but also is possible to specify it in degrees Fahrenheit too.
|
||||||
|
The
|
||||||
|
.Em value
|
||||||
|
argument will have to contain the
|
||||||
|
.Dq degF
|
||||||
|
keyword:
|
||||||
|
.Bd -literal
|
||||||
|
aiboost0:CPU Temperature:critmax:120degF
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
The second example in the configuration file sets the description
|
||||||
|
.Dq CPU Temperature
|
||||||
|
to the sensor
|
||||||
|
.Dq Temp0
|
||||||
|
in the
|
||||||
|
.Dq lm0
|
||||||
|
device.
|
||||||
|
.Pp
|
||||||
|
The last example in the configuration file sets the rfact value to
|
||||||
|
.Em 56000
|
||||||
|
to the
|
||||||
|
.Dq +3.3V
|
||||||
|
sensor in the
|
||||||
|
.Dq smsc0
|
||||||
|
device.
|
||||||
|
.Pp
|
||||||
|
It's possible to set all these properties at boot time with the
|
||||||
|
.Xr rc.d 8
|
||||||
|
script available at
|
||||||
|
.Pa /etc/rc.d/envsys .
|
||||||
|
.Pp
|
||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
Display the
|
Display the
|
||||||
.Do acpibat0 charge
|
.Dq acpibat0 charge
|
||||||
.Dc sensor on one line (row format) every ten seconds:
|
sensor on one line every ten seconds:
|
||||||
.Dl envstat -s \*qacpibat0 charge\*q -r -i 10
|
.Pp
|
||||||
|
.Dl $ envstat -s \*qacpibat0 charge\*q -i 10
|
||||||
|
.Pp
|
||||||
|
Lists the drivers that are currently registered with
|
||||||
|
.Xr envsys 4 :
|
||||||
|
.Pp
|
||||||
|
.Dl $ envstat -D
|
||||||
|
.Pp
|
||||||
|
Display the sensors of the driver
|
||||||
|
.Ar aiboost0 :
|
||||||
|
.Pp
|
||||||
|
.Dl $ envstat -d aiboost0
|
||||||
|
.Pp
|
||||||
|
Change the description string for the
|
||||||
|
.Dq +3.3V
|
||||||
|
sensor to
|
||||||
|
.Dq +3.3 Volts
|
||||||
|
in the
|
||||||
|
.Ar aiboost0
|
||||||
|
device:
|
||||||
|
.Pp
|
||||||
|
.Dl $ envstat -s \*q+3.3V\*q -d aiboost0 -m desc=\*q+3.3 Volts\*q
|
||||||
|
.Pp
|
||||||
|
Set a critical max limit to 60 degC for the
|
||||||
|
.Dq CPU Temp
|
||||||
|
sensor, in the
|
||||||
|
.Ar aiboost0
|
||||||
|
device:
|
||||||
|
.Pp
|
||||||
|
.Dl $ envstat -s \*qCPU Temp\*q -d aiboost0 -m critmax=60
|
||||||
|
.Pp
|
||||||
|
Set a critical min limit to 1000 RPMs for the
|
||||||
|
.Dq CPU Fan
|
||||||
|
sensor, in the
|
||||||
|
.Ar aiboost0
|
||||||
|
device:
|
||||||
|
.Pp
|
||||||
|
.Dl $ envstat -s \*qCPU Fan\*q -d aiboost0 -m critmin=1000
|
||||||
|
.Pp
|
||||||
|
Remove a max critical limit for the
|
||||||
|
.Dq CPU Temp
|
||||||
|
sensor, in the
|
||||||
|
.Ar aiboost0
|
||||||
|
device:
|
||||||
|
.Pp
|
||||||
|
.Dl $ envstat -s \*qCPU Temp\*q -d aiboost0 -m critmax=remove
|
||||||
|
.Pp
|
||||||
|
Change the resistor factor (rfact) to 56000 for the
|
||||||
|
.Dq +3.3V
|
||||||
|
sensor, in the
|
||||||
|
.Ar lm0
|
||||||
|
device:
|
||||||
|
.Pp
|
||||||
|
.Dl $ envstat -s \*q+3.3V\*q -d lm0 -m rfact=56000
|
||||||
|
.Pp
|
||||||
|
Set a critical capacity to
|
||||||
|
.Sy 10%
|
||||||
|
for the
|
||||||
|
.Dq acpibat0 charge
|
||||||
|
sensor, in the
|
||||||
|
.Ar acpibat0
|
||||||
|
device:
|
||||||
|
.Pp
|
||||||
|
.Dl $ envstat -s \*qacpibat0 charge\*q -dacpibat0 -m critical=10
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
|
.Xr proplib 3 ,
|
||||||
.Xr acpiacad 4 ,
|
.Xr acpiacad 4 ,
|
||||||
.Xr acpibat 4 ,
|
.Xr acpibat 4 ,
|
||||||
.Xr acpitz 4 ,
|
.Xr acpitz 4 ,
|
||||||
|
@ -122,10 +343,23 @@ Display the
|
||||||
.Xr owtemp 4 ,
|
.Xr owtemp 4 ,
|
||||||
.Xr sparc/tctrl 4 ,
|
.Xr sparc/tctrl 4 ,
|
||||||
.Xr sparc64/envctrl 4 ,
|
.Xr sparc64/envctrl 4 ,
|
||||||
|
.Xr smsc 4 ,
|
||||||
.Xr tm121temp 4 ,
|
.Xr tm121temp 4 ,
|
||||||
.Xr ug 4 ,
|
.Xr ug 4 ,
|
||||||
.Xr viaenv 4 .
|
.Xr viaenv 4
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
.Nm
|
.Nm
|
||||||
appeared in
|
appeared in
|
||||||
.Nx 1.5 .
|
.Nx 1.5 .
|
||||||
|
It was completely rewritten from scratch for
|
||||||
|
.Nx 5.0 .
|
||||||
|
.Sh AUTHORS
|
||||||
|
.An -nosplit
|
||||||
|
The
|
||||||
|
.Nm
|
||||||
|
utility that appeared in
|
||||||
|
.Nx 5.0
|
||||||
|
was written by
|
||||||
|
.An Juan Romero Pardines .
|
||||||
|
The previous version was written by
|
||||||
|
.An Bill Squier .
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,11 +1,11 @@
|
||||||
# $NetBSD: Makefile,v 1.3 2006/02/05 14:11:18 christos Exp $
|
# $NetBSD: Makefile,v 1.4 2007/07/01 07:39:47 xtraeme Exp $
|
||||||
|
|
||||||
PROG= powerd
|
PROG= powerd
|
||||||
SRCS= powerd.c
|
SRCS= powerd.c
|
||||||
|
|
||||||
WARNS?= 4
|
WARNS?= 4
|
||||||
DPADD+= ${LIBUTIL}
|
DPADD+= ${LIBPROP} ${LIBUTIL}
|
||||||
LDADD+= -lutil
|
LDADD+= -lprop -lutil
|
||||||
|
|
||||||
MAN= powerd.8
|
MAN= powerd.8
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.\" $NetBSD: powerd.8,v 1.9 2006/12/14 02:34:32 reed Exp $
|
.\" $NetBSD: powerd.8,v 1.10 2007/07/01 07:39:47 xtraeme Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 2003 Wasabi Systems, Inc.
|
.\" Copyright (c) 2003 Wasabi Systems, Inc.
|
||||||
.\" All rights reserved.
|
.\" All rights reserved.
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.Dd May 3, 2004
|
.Dd June 15, 2007
|
||||||
.Dt POWERD 8
|
.Dt POWERD 8
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
@ -64,7 +64,7 @@ will stay in the foreground of the controlling terminal.
|
||||||
.El
|
.El
|
||||||
.Sh CONFIGURATION SCRIPTS
|
.Sh CONFIGURATION SCRIPTS
|
||||||
All of
|
All of
|
||||||
.Nm Ns 's
|
.Nm
|
||||||
configuration is encapsulated into scripts that are run when power
|
configuration is encapsulated into scripts that are run when power
|
||||||
management events occur.
|
management events occur.
|
||||||
.Nm
|
.Nm
|
||||||
|
@ -108,7 +108,8 @@ This script is called when an event occurs on a sleep button device.
|
||||||
.It lid_switch
|
.It lid_switch
|
||||||
This script is called when an event occurs on a lid switch device.
|
This script is called when an event occurs on a lid switch device.
|
||||||
.It acadapter
|
.It acadapter
|
||||||
This script is called when an online or offline event occurs on an AC adapter device.
|
This script is called when an online or offline event occurs on an
|
||||||
|
AC adapter device.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
The following events are defined for power switch devices:
|
The following events are defined for power switch devices:
|
||||||
|
@ -126,17 +127,89 @@ when a power button is pressed by the operator:
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
/etc/powerd/scripts/power_button acpi0 pressed
|
/etc/powerd/scripts/power_button acpi0 pressed
|
||||||
.Ed
|
.Ed
|
||||||
|
.Ss ENVSYS SCRIPTS
|
||||||
|
.Xr envsys 4
|
||||||
|
scripts are called when a critical condition was triggered in
|
||||||
|
a sensor.
|
||||||
|
These scripts are called with three arguments: the
|
||||||
|
device associated, the event type, and sensor's name.
|
||||||
|
The
|
||||||
|
.Sy sensor_drive
|
||||||
|
sensor uses a fourth argument: state description.
|
||||||
|
.Pp
|
||||||
|
The following envsys script names are defined:
|
||||||
|
.Bl -tag -width "sensor_temperature"
|
||||||
|
.It sensor_battery
|
||||||
|
This script is called when an event occurs on a battery sensor (Wh/Ah).
|
||||||
|
.It sensor_drive
|
||||||
|
This script is called when an event occurs on a drive sensor.
|
||||||
|
.It sensor_fan
|
||||||
|
This script is called when an event occurs on a fan sensor.
|
||||||
|
.It sensor_power
|
||||||
|
This script is called when an event occurs on a power sensor (W/Ampere).
|
||||||
|
.It sensor_resistance
|
||||||
|
This script is called when an event occurs on a resistance sensor (Ohm).
|
||||||
|
.It sensor_temperature
|
||||||
|
This script is called when an event occurs on a temperature sensor.
|
||||||
|
.It sensor_voltage
|
||||||
|
This script is called when an event occurs on a voltage sensor.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The following event is defined for all scripts but is only sent after
|
||||||
|
a critical/warning or any other event was previously sent:
|
||||||
|
.Bl -tag -width "sensor_temperature"
|
||||||
|
.It normal
|
||||||
|
A normal state/capacity/condition was triggered.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The following events are defined for battery, fan, power, resistance,
|
||||||
|
temperature, and voltage sensors:
|
||||||
|
.Bl -tag -width "sensor_temperature"
|
||||||
|
.It critical
|
||||||
|
A critical condition was triggered.
|
||||||
|
.It critical-under
|
||||||
|
A critical under condition was triggered.
|
||||||
|
.It critical-over
|
||||||
|
A critical over condition was triggered.
|
||||||
|
.It warning-under
|
||||||
|
A warning under condition was triggered.
|
||||||
|
.It warning-over
|
||||||
|
A warning over condition was triggered.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The following events are defined for battery sensors:
|
||||||
|
.Bl -tag -width "sensor_temperature"
|
||||||
|
.It user-capacity
|
||||||
|
A capacity limit set by the user was triggered.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The following events are defined for drive sensors:
|
||||||
|
.Bl -tag -width "sensor_temperature"
|
||||||
|
.It state-changed
|
||||||
|
The state on the sensor changed and it's not in a valid state.
|
||||||
|
.El
|
||||||
|
.Pp
|
||||||
|
The following is an example of how a temperature sensor script might be
|
||||||
|
invoked when a critical over condition is triggered:
|
||||||
|
.Bd -literal -offset indent
|
||||||
|
/etc/powerd/scripts/sensor_temperature lm0 critical-over "CPU Temp"
|
||||||
|
.Ed
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr acpi 4 ,
|
.Xr acpi 4 ,
|
||||||
.Xr acpiacad 4 ,
|
.Xr acpiacad 4 ,
|
||||||
.Xr acpibut 4 ,
|
.Xr acpibut 4 ,
|
||||||
.Xr acpilid 4 ,
|
.Xr acpilid 4 ,
|
||||||
.Xr apm 4
|
.Xr envsys 4 ,
|
||||||
|
.Xr i386/apm 4
|
||||||
.\" .Xr sysmon 4
|
.\" .Xr sysmon 4
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
.Nm
|
.Nm
|
||||||
first appeared in
|
first appeared in
|
||||||
.Nx 2.0 .
|
.Nx 2.0 .
|
||||||
|
Support to handle
|
||||||
|
.Xr envsys 4
|
||||||
|
events appeared in
|
||||||
|
.Nx 5.0 .
|
||||||
.Sh AUTHORS
|
.Sh AUTHORS
|
||||||
.Nm
|
.Nm
|
||||||
was written by
|
was written by
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: powerd.c,v 1.7 2007/05/07 02:33:35 xtraeme Exp $ */
|
/* $NetBSD: powerd.c,v 1.8 2007/07/01 07:39:47 xtraeme Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2003 Wasabi Systems, Inc.
|
* Copyright (c) 2003 Wasabi Systems, Inc.
|
||||||
|
@ -52,6 +52,7 @@
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
|
#include <prop/proplib.h>
|
||||||
|
|
||||||
int debug;
|
int debug;
|
||||||
|
|
||||||
|
@ -65,7 +66,7 @@ static void run_script(const char *[]);
|
||||||
static struct kevent *allocchange(void);
|
static struct kevent *allocchange(void);
|
||||||
static int wait_for_events(struct kevent *, size_t);
|
static int wait_for_events(struct kevent *, size_t);
|
||||||
static void dispatch_dev_power(struct kevent *);
|
static void dispatch_dev_power(struct kevent *);
|
||||||
static void dispatch_power_event_switch_state_change(power_event_t *);
|
static void dispatch_power_event_state_change(int, power_event_t *);
|
||||||
|
|
||||||
static const char *script_paths[] = {
|
static const char *script_paths[] = {
|
||||||
NULL,
|
NULL,
|
||||||
|
@ -250,47 +251,6 @@ wait_for_events(struct kevent *events, size_t nevents)
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
|
||||||
pswitch_type_name(int type)
|
|
||||||
{
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case PSWITCH_TYPE_POWER:
|
|
||||||
return "power_button";
|
|
||||||
|
|
||||||
case PSWITCH_TYPE_SLEEP:
|
|
||||||
return "sleep_button";
|
|
||||||
|
|
||||||
case PSWITCH_TYPE_LID:
|
|
||||||
return "lid_switch";
|
|
||||||
|
|
||||||
case PSWITCH_TYPE_RESET:
|
|
||||||
return "reset_button";
|
|
||||||
|
|
||||||
case PSWITCH_TYPE_ACADAPTER:
|
|
||||||
return "acadapter";
|
|
||||||
|
|
||||||
default:
|
|
||||||
return "=unknown pswitch type=";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *
|
|
||||||
pswitch_event_name(int type)
|
|
||||||
{
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case PSWITCH_EVENT_PRESSED:
|
|
||||||
return "pressed";
|
|
||||||
|
|
||||||
case PSWITCH_EVENT_RELEASED:
|
|
||||||
return "released";
|
|
||||||
|
|
||||||
default:
|
|
||||||
return "=unknown pswitch event=";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dispatch_dev_power(struct kevent *ev)
|
dispatch_dev_power(struct kevent *ev)
|
||||||
{
|
{
|
||||||
|
@ -298,8 +258,9 @@ dispatch_dev_power(struct kevent *ev)
|
||||||
int fd = ev->ident;
|
int fd = ev->ident;
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
(void)fprintf(stderr, "dispatch_dev_power: %" PRId64
|
(void)fprintf(stderr, "%s: %" PRId64
|
||||||
" events available\n", ev->data);
|
" event%s available\n", __func__,
|
||||||
|
ev->data, ev->data > 1 ? "s" : "");
|
||||||
|
|
||||||
again:
|
again:
|
||||||
if (read(fd, &pev, sizeof(pev)) != sizeof(pev)) {
|
if (read(fd, &pev, sizeof(pev)) != sizeof(pev)) {
|
||||||
|
@ -309,16 +270,15 @@ dispatch_dev_power(struct kevent *ev)
|
||||||
exit(EX_OSERR);
|
exit(EX_OSERR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) {
|
if (debug)
|
||||||
(void)fprintf(stderr, "dispatch_dev_power: event type %d\n",
|
(void)fprintf(stderr, "%s: event type %d\n",
|
||||||
pev.pev_type);
|
__func__, pev.pev_type);
|
||||||
}
|
|
||||||
|
|
||||||
switch (pev.pev_type) {
|
switch (pev.pev_type) {
|
||||||
|
case POWER_EVENT_ENVSYS_STATE_CHANGE:
|
||||||
case POWER_EVENT_SWITCH_STATE_CHANGE:
|
case POWER_EVENT_SWITCH_STATE_CHANGE:
|
||||||
dispatch_power_event_switch_state_change(&pev);
|
dispatch_power_event_state_change(fd, &pev);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
syslog(LOG_INFO, "unknown %s event type: %d",
|
syslog(LOG_INFO, "unknown %s event type: %d",
|
||||||
_PATH_DEV_POWER, pev.pev_type);
|
_PATH_DEV_POWER, pev.pev_type);
|
||||||
|
@ -328,18 +288,42 @@ dispatch_dev_power(struct kevent *ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dispatch_power_event_switch_state_change(power_event_t *pev)
|
dispatch_power_event_state_change(int fd, power_event_t *pev)
|
||||||
{
|
{
|
||||||
const char *argv[4];
|
prop_dictionary_t dict;
|
||||||
|
prop_object_t obj;
|
||||||
|
const char *argv[6];
|
||||||
|
int error;
|
||||||
|
|
||||||
argv[0] = pswitch_type_name(pev->pev_switch.psws_type);
|
error = prop_dictionary_recv_ioctl(fd, POWER_EVENT_RECVDICT, &dict);
|
||||||
argv[1] = pev->pev_switch.psws_name;
|
if (error) {
|
||||||
argv[2] = pswitch_event_name(pev->pev_switch.psws_state);
|
if (debug)
|
||||||
argv[3] = NULL;
|
printf("%s: prop_dictionary_recv_ioctl error=%d\n",
|
||||||
|
__func__, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (debug)
|
if (debug)
|
||||||
(void)fprintf(stderr, "%s on %s %s\n", argv[0], argv[1],
|
printf("%s", prop_dictionary_externalize(dict));
|
||||||
argv[2]);
|
|
||||||
|
obj = prop_dictionary_get(dict, "powerd-script-name");
|
||||||
|
argv[0] = prop_string_cstring_nocopy(obj);
|
||||||
|
|
||||||
|
obj = prop_dictionary_get(dict, "driver-name");
|
||||||
|
argv[1] = prop_string_cstring_nocopy(obj);
|
||||||
|
|
||||||
|
obj = prop_dictionary_get(dict, "powerd-event-name");
|
||||||
|
argv[2] = prop_string_cstring_nocopy(obj);
|
||||||
|
|
||||||
|
obj = prop_dictionary_get(dict, "sensor-name");
|
||||||
|
argv[3] = prop_string_cstring_nocopy(obj);
|
||||||
|
|
||||||
|
obj = prop_dictionary_get(dict, "drive-state-desc");
|
||||||
|
argv[4] = prop_string_cstring_nocopy(obj);
|
||||||
|
|
||||||
|
argv[5] = NULL;
|
||||||
|
|
||||||
|
prop_object_release(dict);
|
||||||
|
|
||||||
run_script(argv);
|
run_script(argv);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue