summaryrefslogtreecommitdiffstats
path: root/usr.sbin/apmd/apmdparse.y
diff options
context:
space:
mode:
authornsayer <nsayer@FreeBSD.org>2001-05-15 05:13:45 +0000
committernsayer <nsayer@FreeBSD.org>2001-05-15 05:13:45 +0000
commitb5081db59bef2818c352f77a726f2d105b638847 (patch)
tree6a2076a6d6331e348a9a0f5a870a063402e0babd /usr.sbin/apmd/apmdparse.y
parent2bdf180df8cc9444b255a01377516bec3cd373bd (diff)
downloadFreeBSD-src-b5081db59bef2818c352f77a726f2d105b638847.zip
FreeBSD-src-b5081db59bef2818c352f77a726f2d105b638847.tar.gz
Add battery state monitoring to apmd.
The new syntax available in the config file is: apm_battery [0-9]+(%|[Mm) (dis|)charging { ... } The stuff in the braces is the same as the existing case. nn% checks for a certain percentage of life remaining and nnM checks for a cerain number of minutes remaining. Specifying "discharge" means that you're interested in knowing when the battery reaches a certain level while AC power is off, "charging" the opposite. The man page needs to be updated. The code can be fooled. If you SIGHUP the daemon and the battery level matches a rule it will be performed once per SIGHUP. If the battery level matches a rule and you repeatedly apply and take away AC power, the rule will be run once per occurance. This, however, is a feature. :-) The code also only runs when select() times out, so getting APM events more often than the timeout interval will result in the rules not being run. These are things that remain to be overcome.
Diffstat (limited to 'usr.sbin/apmd/apmdparse.y')
-rw-r--r--usr.sbin/apmd/apmdparse.y39
1 files changed, 39 insertions, 0 deletions
diff --git a/usr.sbin/apmd/apmdparse.y b/usr.sbin/apmd/apmdparse.y
index ce9c9dc..f0acea3 100644
--- a/usr.sbin/apmd/apmdparse.y
+++ b/usr.sbin/apmd/apmdparse.y
@@ -32,6 +32,7 @@
#include <stdio.h>
#include <bitstring.h>
+#include <stdlib.h>
#include "apmd.h"
#ifdef DEBUG
@@ -47,15 +48,21 @@ extern int first_time;
bitstr_t bit_decl(evlist, EVENT_MAX);
int ev;
struct event_cmd * evcmd;
+ int i;
}
%token BEGINBLOCK ENDBLOCK
%token COMMA SEMICOLON
%token APMEVENT
+%token APMBATT
+%token BATTCHARGE BATTDISCHARGE
+%token <str> BATTTIME BATTPERCENT
%token EXECCMD REJECTCMD
%token <ev> EVENT
%token <str> STRING UNKNOWN
+%type <i> apm_battery_level
+%type <i> apm_battery_direction
%type <str> string
%type <str> unknown
%type <evlist> event_list
@@ -76,6 +83,7 @@ config_list
config
: apm_event_statement
+ | apm_battery_statement
;
apm_event_statement
@@ -87,6 +95,37 @@ apm_event_statement
}
;
+apm_battery_level
+ : BATTPERCENT
+ {
+ $$ = $1;
+ }
+ | BATTTIME
+ {
+ $$ = $1;
+ }
+ ;
+
+apm_battery_direction
+ : BATTCHARGE
+ {
+ $$ = 1;
+ }
+ | BATTDISCHARGE
+ {
+ $$ = -1;
+ }
+ ;
+apm_battery_statement
+ : APMBATT apm_battery_level apm_battery_direction
+ BEGINBLOCK cmd_list ENDBLOCK
+ {
+ if (register_battery_handlers($2, $3, $5) < 0)
+ abort(); /* XXX */
+ free_event_cmd_list($5);
+ }
+ ;
+
event_list
: EVENT
{
OpenPOWER on IntegriCloud