summaryrefslogtreecommitdiff
path: root/usr.sbin/powerd
diff options
context:
space:
mode:
authorxtraeme <xtraeme@NetBSD.org>2007-07-01 07:39:45 +0000
committerxtraeme <xtraeme@NetBSD.org>2007-07-01 07:39:45 +0000
commitaf211bb4e3c79fdc4e4644b7acb8564151316a4d (patch)
treebc4250211dd14debde531558d27682404fe1b757 /usr.sbin/powerd
parentda3f163bd280223c1d17fd1ff78946be2df177b8 (diff)
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).
Diffstat (limited to 'usr.sbin/powerd')
-rw-r--r--usr.sbin/powerd/Makefile6
-rw-r--r--usr.sbin/powerd/powerd.883
-rw-r--r--usr.sbin/powerd/powerd.c104
3 files changed, 125 insertions, 68 deletions
diff --git a/usr.sbin/powerd/Makefile b/usr.sbin/powerd/Makefile
index f878aeadd51..ff40e7e0b85 100644
--- a/usr.sbin/powerd/Makefile
+++ b/usr.sbin/powerd/Makefile
@@ -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
SRCS= powerd.c
WARNS?= 4
-DPADD+= ${LIBUTIL}
-LDADD+= -lutil
+DPADD+= ${LIBPROP} ${LIBUTIL}
+LDADD+= -lprop -lutil
MAN= powerd.8
diff --git a/usr.sbin/powerd/powerd.8 b/usr.sbin/powerd/powerd.8
index 1303ccf8e1a..8a244663887 100644
--- a/usr.sbin/powerd/powerd.8
+++ b/usr.sbin/powerd/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.
.\" All rights reserved.
@@ -33,7 +33,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd May 3, 2004
+.Dd June 15, 2007
.Dt POWERD 8
.Os
.Sh NAME
@@ -64,7 +64,7 @@ will stay in the foreground of the controlling terminal.
.El
.Sh CONFIGURATION SCRIPTS
All of
-.Nm Ns 's
+.Nm
configuration is encapsulated into scripts that are run when power
management events occur.
.Nm
@@ -108,7 +108,8 @@ This script is called when an event occurs on a sleep button device.
.It lid_switch
This script is called when an event occurs on a lid switch device.
.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
.Pp
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
/etc/powerd/scripts/power_button acpi0 pressed
.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
.Xr acpi 4 ,
.Xr acpiacad 4 ,
.Xr acpibut 4 ,
.Xr acpilid 4 ,
-.Xr apm 4
+.Xr envsys 4 ,
+.Xr i386/apm 4
.\" .Xr sysmon 4
.Sh HISTORY
.Nm
first appeared in
.Nx 2.0 .
+Support to handle
+.Xr envsys 4
+events appeared in
+.Nx 5.0 .
.Sh AUTHORS
.Nm
was written by
diff --git a/usr.sbin/powerd/powerd.c b/usr.sbin/powerd/powerd.c
index 9ed4b50beaa..8842b937256 100644
--- a/usr.sbin/powerd/powerd.c
+++ b/usr.sbin/powerd/powerd.c
@@ -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.
@@ -52,6 +52,7 @@
#include <syslog.h>
#include <unistd.h>
#include <util.h>
+#include <prop/proplib.h>
int debug;
@@ -65,7 +66,7 @@ static void run_script(const char *[]);
static struct kevent *allocchange(void);
static int wait_for_events(struct kevent *, size_t);
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[] = {
NULL,
@@ -250,47 +251,6 @@ wait_for_events(struct kevent *events, size_t nevents)
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
dispatch_dev_power(struct kevent *ev)
{
@@ -298,8 +258,9 @@ dispatch_dev_power(struct kevent *ev)
int fd = ev->ident;
if (debug)
- (void)fprintf(stderr, "dispatch_dev_power: %" PRId64
- " events available\n", ev->data);
+ (void)fprintf(stderr, "%s: %" PRId64
+ " event%s available\n", __func__,
+ ev->data, ev->data > 1 ? "s" : "");
again:
if (read(fd, &pev, sizeof(pev)) != sizeof(pev)) {
@@ -309,16 +270,15 @@ dispatch_dev_power(struct kevent *ev)
exit(EX_OSERR);
}
- if (debug) {
- (void)fprintf(stderr, "dispatch_dev_power: event type %d\n",
- pev.pev_type);
- }
+ if (debug)
+ (void)fprintf(stderr, "%s: event type %d\n",
+ __func__, pev.pev_type);
switch (pev.pev_type) {
+ case POWER_EVENT_ENVSYS_STATE_CHANGE:
case POWER_EVENT_SWITCH_STATE_CHANGE:
- dispatch_power_event_switch_state_change(&pev);
+ dispatch_power_event_state_change(fd, &pev);
break;
-
default:
syslog(LOG_INFO, "unknown %s event type: %d",
_PATH_DEV_POWER, pev.pev_type);
@@ -328,18 +288,42 @@ dispatch_dev_power(struct kevent *ev)
}
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;
+
+ error = prop_dictionary_recv_ioctl(fd, POWER_EVENT_RECVDICT, &dict);
+ if (error) {
+ if (debug)
+ printf("%s: prop_dictionary_recv_ioctl error=%d\n",
+ __func__, error);
+ return;
+ }
+
+ if (debug)
+ printf("%s", prop_dictionary_externalize(dict));
- argv[0] = pswitch_type_name(pev->pev_switch.psws_type);
- argv[1] = pev->pev_switch.psws_name;
- argv[2] = pswitch_event_name(pev->pev_switch.psws_state);
- argv[3] = NULL;
+ obj = prop_dictionary_get(dict, "powerd-script-name");
+ argv[0] = prop_string_cstring_nocopy(obj);
- if (debug)
- (void)fprintf(stderr, "%s on %s %s\n", argv[0], argv[1],
- argv[2]);
+ 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);
}