2013-02-09 05:16:39 +04:00
|
|
|
/* $NetBSD: powerd.c,v 1.18 2013/02/09 01:16:39 christos Exp $ */
|
2003-04-18 08:54:49 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2003 Wasabi Systems, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Jason R. Thorpe for Wasabi Systems, Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed for the NetBSD Project by
|
|
|
|
* Wasabi Systems, Inc.
|
|
|
|
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Power management daemon for sysmon.
|
|
|
|
*/
|
|
|
|
|
2010-12-15 20:12:40 +03:00
|
|
|
#define SYSLOG_NAMES
|
|
|
|
|
2007-05-07 06:33:35 +04:00
|
|
|
#include <sys/cdefs.h>
|
2010-12-20 01:52:08 +03:00
|
|
|
#include <sys/ioctl.h>
|
2003-04-18 08:54:49 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/event.h>
|
|
|
|
#include <sys/power.h>
|
|
|
|
#include <sys/wait.h>
|
2010-12-20 01:52:08 +03:00
|
|
|
#include <err.h>
|
2003-04-18 08:54:49 +04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2010-04-25 00:44:33 +04:00
|
|
|
#include <paths.h>
|
2003-04-18 08:54:49 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sysexits.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <util.h>
|
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).
2007-07-01 11:39:45 +04:00
|
|
|
#include <prop/proplib.h>
|
2010-12-15 20:12:40 +03:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
2003-04-18 08:54:49 +04:00
|
|
|
|
2010-12-20 01:52:08 +03:00
|
|
|
#include "prog_ops.h"
|
|
|
|
|
2010-12-15 20:12:40 +03:00
|
|
|
int debug, no_scripts;
|
2003-04-18 08:54:49 +04:00
|
|
|
|
|
|
|
static int kq;
|
|
|
|
|
|
|
|
#define _PATH_POWERD_SCRIPTS "/etc/powerd/scripts"
|
|
|
|
|
2007-12-15 22:44:37 +03:00
|
|
|
static void usage(void) __dead;
|
2003-04-18 08:54:49 +04:00
|
|
|
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 *);
|
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).
2007-07-01 11:39:45 +04:00
|
|
|
static void dispatch_power_event_state_change(int, power_event_t *);
|
2012-03-15 06:02:20 +04:00
|
|
|
static void powerd_log(int, const char *, ...) __printflike(2, 3);
|
2003-04-18 08:54:49 +04:00
|
|
|
|
|
|
|
static const char *script_paths[] = {
|
|
|
|
NULL,
|
|
|
|
_PATH_POWERD_SCRIPTS
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct kevent *ev, events[16];
|
|
|
|
struct power_type power_type;
|
|
|
|
char *cp;
|
|
|
|
int ch, fd;
|
|
|
|
|
2006-02-05 17:03:46 +03:00
|
|
|
setprogname(*argv);
|
|
|
|
|
2010-12-20 01:52:08 +03:00
|
|
|
if (prog_init && prog_init() == -1)
|
|
|
|
err(1, "init failed");
|
|
|
|
|
2010-12-15 20:12:40 +03:00
|
|
|
while ((ch = getopt(argc, argv, "dn")) != -1) {
|
2003-04-18 08:54:49 +04:00
|
|
|
switch (ch) {
|
|
|
|
case 'd':
|
|
|
|
debug = 1;
|
|
|
|
break;
|
|
|
|
|
2010-12-15 20:12:40 +03:00
|
|
|
case 'n':
|
|
|
|
no_scripts = 1;
|
|
|
|
break;
|
|
|
|
|
2003-04-18 08:54:49 +04:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc)
|
|
|
|
usage();
|
|
|
|
|
2010-12-15 20:12:40 +03:00
|
|
|
if (debug == 0) {
|
2006-02-05 17:03:46 +03:00
|
|
|
(void)daemon(0, 0);
|
2003-04-18 08:54:49 +04:00
|
|
|
|
2010-12-15 20:12:40 +03:00
|
|
|
openlog("powerd", LOG_PID | LOG_NOWAIT, LOG_DAEMON);
|
|
|
|
(void)pidfile(NULL);
|
|
|
|
}
|
2003-04-18 08:54:49 +04:00
|
|
|
|
2010-12-20 01:52:08 +03:00
|
|
|
if ((kq = prog_kqueue()) == -1) {
|
2010-12-15 20:12:40 +03:00
|
|
|
powerd_log(LOG_ERR, "kqueue: %s", strerror(errno));
|
2003-04-18 08:54:49 +04:00
|
|
|
exit(EX_OSERR);
|
|
|
|
}
|
|
|
|
|
2010-12-20 01:52:08 +03:00
|
|
|
if ((fd = prog_open(_PATH_POWER, O_RDONLY|O_NONBLOCK, 0600)) == -1) {
|
2010-12-15 20:12:40 +03:00
|
|
|
powerd_log(LOG_ERR, "open %s: %s", _PATH_POWER,
|
|
|
|
strerror(errno));
|
2003-04-18 08:54:49 +04:00
|
|
|
exit(EX_OSERR);
|
|
|
|
}
|
|
|
|
|
2010-12-20 01:52:08 +03:00
|
|
|
if (prog_fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) {
|
2010-12-15 20:12:40 +03:00
|
|
|
powerd_log(LOG_ERR, "Cannot set close on exec in power fd: %s",
|
|
|
|
strerror(errno));
|
2006-02-05 17:03:46 +03:00
|
|
|
exit(EX_OSERR);
|
|
|
|
}
|
|
|
|
|
2010-12-20 01:52:08 +03:00
|
|
|
if (prog_ioctl(fd, POWER_IOC_GET_TYPE, &power_type) == -1) {
|
2010-12-15 20:12:40 +03:00
|
|
|
powerd_log(LOG_ERR, "POWER_IOC_GET_TYPE: %s", strerror(errno));
|
2003-04-18 08:54:49 +04:00
|
|
|
exit(EX_OSERR);
|
|
|
|
}
|
|
|
|
|
2006-02-05 17:03:46 +03:00
|
|
|
(void)asprintf(&cp, "%s/%s", _PATH_POWERD_SCRIPTS,
|
|
|
|
power_type.power_type);
|
2003-04-18 08:54:49 +04:00
|
|
|
if (cp == NULL) {
|
2010-12-15 20:12:40 +03:00
|
|
|
powerd_log(LOG_ERR, "allocating script path: %s",
|
|
|
|
strerror(errno));
|
2003-04-18 08:54:49 +04:00
|
|
|
exit(EX_OSERR);
|
|
|
|
}
|
|
|
|
script_paths[0] = cp;
|
|
|
|
|
|
|
|
ev = allocchange();
|
|
|
|
EV_SET(ev, fd, EVFILT_READ, EV_ADD | EV_ENABLE,
|
|
|
|
0, 0, (intptr_t) dispatch_dev_power);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
void (*handler)(struct kevent *);
|
|
|
|
int i, rv;
|
|
|
|
|
2007-05-07 06:33:35 +04:00
|
|
|
rv = wait_for_events(events, __arraycount(events));
|
2003-04-18 08:54:49 +04:00
|
|
|
for (i = 0; i < rv; i++) {
|
|
|
|
handler = (void *) events[i].udata;
|
|
|
|
(*handler)(&events[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
|
2010-12-15 20:12:40 +03:00
|
|
|
(void)fprintf(stderr, "usage: %s [-dn]\n", getprogname());
|
2003-04-18 08:54:49 +04:00
|
|
|
exit(EX_USAGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
run_script(const char *argv[])
|
|
|
|
{
|
|
|
|
char path[MAXPATHLEN+1];
|
2006-02-05 17:03:46 +03:00
|
|
|
size_t i, j;
|
2003-04-18 08:54:49 +04:00
|
|
|
|
2007-05-07 06:33:35 +04:00
|
|
|
for (i = 0; i < __arraycount(script_paths); i++) {
|
2006-02-05 17:03:46 +03:00
|
|
|
(void)snprintf(path, sizeof(path), "%s/%s", script_paths[i],
|
|
|
|
argv[0]);
|
2003-04-18 08:54:49 +04:00
|
|
|
if (access(path, R_OK|X_OK) == 0) {
|
|
|
|
int status;
|
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
argv[0] = path;
|
|
|
|
|
|
|
|
if (debug) {
|
2010-12-15 20:12:40 +03:00
|
|
|
(void)fprintf(stderr, "%srunning script: %s",
|
|
|
|
no_scripts?"not ":"", argv[0]);
|
2006-02-05 17:03:46 +03:00
|
|
|
for (j = 1; argv[j] != NULL; j++)
|
|
|
|
(void)fprintf(stderr, " %s", argv[j]);
|
|
|
|
(void)fprintf(stderr, "\n");
|
2003-04-18 08:54:49 +04:00
|
|
|
}
|
2010-12-15 20:12:40 +03:00
|
|
|
if (no_scripts != 0)
|
|
|
|
return;
|
2003-04-18 08:54:49 +04:00
|
|
|
|
|
|
|
switch ((pid = vfork())) {
|
|
|
|
case -1:
|
2010-12-15 20:12:40 +03:00
|
|
|
powerd_log(LOG_ERR, "fork to run script: %s",
|
|
|
|
strerror(errno));
|
2003-04-18 08:54:49 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
/* Child. */
|
2006-02-05 17:11:18 +03:00
|
|
|
(void) execv(path, __UNCONST(argv));
|
2003-04-18 08:54:49 +04:00
|
|
|
_exit(1);
|
|
|
|
/* NOTREACHED */
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Parent. */
|
2006-02-05 17:03:46 +03:00
|
|
|
if (waitpid(pid, &status, 0) == -1) {
|
2010-12-15 20:12:40 +03:00
|
|
|
powerd_log(LOG_ERR,
|
|
|
|
"waitpid for %s: %s", path,
|
|
|
|
strerror(errno));
|
2006-02-05 17:03:46 +03:00
|
|
|
break;
|
|
|
|
}
|
2003-04-18 08:54:49 +04:00
|
|
|
if (WIFEXITED(status) &&
|
|
|
|
WEXITSTATUS(status) != 0) {
|
2010-12-15 20:12:40 +03:00
|
|
|
powerd_log(LOG_ERR,
|
2003-04-18 08:54:49 +04:00
|
|
|
"%s exited with status %d",
|
|
|
|
path, WEXITSTATUS(status));
|
|
|
|
} else if (!WIFEXITED(status)) {
|
2010-12-15 20:12:40 +03:00
|
|
|
powerd_log(LOG_ERR,
|
2003-04-18 08:54:49 +04:00
|
|
|
"%s terminated abnormally", path);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-15 20:12:40 +03:00
|
|
|
powerd_log(LOG_ERR, "no script for %s", argv[0]);
|
2003-04-18 08:54:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct kevent changebuf[8];
|
2006-02-05 17:03:46 +03:00
|
|
|
static size_t nchanges;
|
2003-04-18 08:54:49 +04:00
|
|
|
|
|
|
|
static struct kevent *
|
|
|
|
allocchange(void)
|
|
|
|
{
|
|
|
|
|
2007-05-07 06:33:35 +04:00
|
|
|
if (nchanges == __arraycount(changebuf)) {
|
2006-02-05 17:03:46 +03:00
|
|
|
(void)wait_for_events(NULL, 0);
|
2003-04-18 08:54:49 +04:00
|
|
|
nchanges = 0;
|
|
|
|
}
|
|
|
|
|
2006-02-05 17:03:46 +03:00
|
|
|
return &changebuf[nchanges++];
|
2003-04-18 08:54:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
wait_for_events(struct kevent *events, size_t nevents)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
2010-12-20 01:52:08 +03:00
|
|
|
while ((rv = prog_kevent(kq, nchanges ? changebuf : NULL, nchanges,
|
2006-02-05 17:03:46 +03:00
|
|
|
events, nevents, NULL)) < 0) {
|
2003-04-18 08:54:49 +04:00
|
|
|
nchanges = 0;
|
|
|
|
if (errno != EINTR) {
|
2010-12-15 20:12:40 +03:00
|
|
|
powerd_log(LOG_ERR, "kevent: %s", strerror(errno));
|
2003-04-18 08:54:49 +04:00
|
|
|
exit(EX_OSERR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-05 17:03:46 +03:00
|
|
|
return rv;
|
2003-04-18 08:54:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dispatch_dev_power(struct kevent *ev)
|
|
|
|
{
|
|
|
|
power_event_t pev;
|
|
|
|
int fd = ev->ident;
|
|
|
|
|
|
|
|
if (debug)
|
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).
2007-07-01 11:39:45 +04:00
|
|
|
(void)fprintf(stderr, "%s: %" PRId64
|
|
|
|
" event%s available\n", __func__,
|
|
|
|
ev->data, ev->data > 1 ? "s" : "");
|
2003-04-18 08:54:49 +04:00
|
|
|
|
|
|
|
again:
|
2010-12-20 01:52:08 +03:00
|
|
|
if (prog_read(fd, &pev, sizeof(pev)) != sizeof(pev)) {
|
2003-04-18 08:54:49 +04:00
|
|
|
if (errno == EWOULDBLOCK)
|
|
|
|
return;
|
2010-12-15 20:12:40 +03:00
|
|
|
powerd_log(LOG_ERR, "read of %s: %s", _PATH_POWER,
|
|
|
|
strerror(errno));
|
2003-04-18 08:54:49 +04:00
|
|
|
exit(EX_OSERR);
|
|
|
|
}
|
|
|
|
|
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).
2007-07-01 11:39:45 +04:00
|
|
|
if (debug)
|
|
|
|
(void)fprintf(stderr, "%s: event type %d\n",
|
|
|
|
__func__, pev.pev_type);
|
2003-04-18 08:54:49 +04:00
|
|
|
|
|
|
|
switch (pev.pev_type) {
|
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).
2007-07-01 11:39:45 +04:00
|
|
|
case POWER_EVENT_ENVSYS_STATE_CHANGE:
|
2003-04-18 08:54:49 +04:00
|
|
|
case POWER_EVENT_SWITCH_STATE_CHANGE:
|
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).
2007-07-01 11:39:45 +04:00
|
|
|
dispatch_power_event_state_change(fd, &pev);
|
2003-04-18 08:54:49 +04:00
|
|
|
break;
|
|
|
|
default:
|
2010-12-15 20:12:40 +03:00
|
|
|
powerd_log(LOG_INFO, "unknown %s event type: %d",
|
2010-04-25 00:44:33 +04:00
|
|
|
_PATH_POWER, pev.pev_type);
|
2003-04-18 08:54:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
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).
2007-07-01 11:39:45 +04:00
|
|
|
dispatch_power_event_state_change(int fd, power_event_t *pev)
|
2003-04-18 08:54:49 +04:00
|
|
|
{
|
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).
2007-07-01 11:39:45 +04:00
|
|
|
prop_dictionary_t dict;
|
|
|
|
prop_object_t obj;
|
|
|
|
const char *argv[6];
|
2007-09-27 22:08:32 +04:00
|
|
|
char *buf = NULL;
|
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).
2007-07-01 11:39:45 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-09-27 22:08:32 +04:00
|
|
|
if (debug) {
|
|
|
|
buf = prop_dictionary_externalize(dict);
|
|
|
|
printf("%s", buf);
|
2007-09-27 22:11:05 +04:00
|
|
|
free(buf);
|
2007-09-27 22:08:32 +04:00
|
|
|
}
|
2003-04-18 08:54:49 +04:00
|
|
|
|
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).
2007-07-01 11:39:45 +04:00
|
|
|
obj = prop_dictionary_get(dict, "powerd-script-name");
|
|
|
|
argv[0] = prop_string_cstring_nocopy(obj);
|
2003-04-18 08:54:49 +04:00
|
|
|
|
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).
2007-07-01 11:39:45 +04:00
|
|
|
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);
|
|
|
|
|
2007-09-04 20:54:37 +04:00
|
|
|
obj = prop_dictionary_get(dict, "state-description");
|
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).
2007-07-01 11:39:45 +04:00
|
|
|
argv[4] = prop_string_cstring_nocopy(obj);
|
|
|
|
|
|
|
|
argv[5] = NULL;
|
|
|
|
|
2003-04-18 08:54:49 +04:00
|
|
|
run_script(argv);
|
|
|
|
}
|
2010-12-15 20:12:40 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
powerd_log(int pri, const char *msg, ...)
|
|
|
|
{
|
|
|
|
va_list arglist;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
va_start(arglist, msg);
|
|
|
|
if (debug == 0)
|
|
|
|
vsyslog(pri, msg, arglist);
|
|
|
|
else {
|
|
|
|
for (i = 0; i < __arraycount(prioritynames); i++)
|
|
|
|
if (prioritynames[i].c_val == pri)
|
|
|
|
break;
|
|
|
|
fprintf(stderr, "%s: ",
|
|
|
|
(prioritynames[i].c_val == -1) ?
|
|
|
|
"UNKNOWN" : prioritynames[i].c_name);
|
|
|
|
vfprintf(stderr, msg, arglist);
|
|
|
|
}
|
2013-02-09 05:16:39 +04:00
|
|
|
va_end(arglist);
|
2010-12-15 20:12:40 +03:00
|
|
|
}
|