From 0a3efd3cdaa1aa72b999739cfac8261b61af3a62 Mon Sep 17 00:00:00 2001 From: skeezix Date: Wed, 17 Feb 2010 22:26:04 -0500 Subject: [PATCH] Added critical battery level forced shutdown .. calls script when battery gets to (say) 1% configured in evmapper conf --- apps/pndevmapperd.c | 29 ++++++++++++++++++++++++++++ deployment/etc/pandora/conf/eventmap | 2 ++ testdata/conf/eventmap | 2 ++ 3 files changed, 33 insertions(+) diff --git a/apps/pndevmapperd.c b/apps/pndevmapperd.c index f09cbfe..713b819 100644 --- a/apps/pndevmapperd.c +++ b/apps/pndevmapperd.c @@ -105,6 +105,8 @@ unsigned int b_frequency = 300; // frequency to check unsigned int b_blinkfreq = 2; // blink every 2sec unsigned int b_blinkdur = 1000; // blink duration (uSec), 0sec + uSec is assumed unsigned char b_active = 0; // 0=inactive, 1=active and waiting to blink, 2=blink is on, waiting to turn off +unsigned char b_shutdown = 1; // %age battery to force a shutdown! +char *b_shutdown_script = NULL; /* get to it */ @@ -368,6 +370,14 @@ int main ( int argc, char *argv[] ) { pnd_log ( pndn_rem, "Battery blink duration set to %u", b_blinkdur ); } b_active = 0; + if ( pnd_conf_get_as_int ( evmaph, "battery.shutdown_threshold" ) != PND_CONF_BADNUM ) { + b_shutdown = pnd_conf_get_as_int ( evmaph, "battery.shutdown_threshold" ); + pnd_log ( pndn_rem, "Battery shutdown threshold set to %u", b_shutdown ); + } + if ( pnd_conf_get_as_char ( evmaph, "battery.shutdown_script" ) != NULL ) { + b_shutdown_script = strdup ( pnd_conf_get_as_char ( evmaph, "battery.shutdown_script" ) ); + pnd_log ( pndn_rem, "Battery shutdown script set to %s", b_shutdown_script ); + } /* do we have anything to do? */ @@ -742,6 +752,25 @@ void sigalrm_handler ( int n ) { batlevel = 4; // low, but not cause a shutdown } + // first -- are we critical yet? if so, shut down! + if ( batlevel <= b_shutdown ) { + int x; + + pnd_log ( pndn_error, "CRITICAL BATTERY LEVEL -- shutdown the system down! Invoke: %s\n", b_shutdown_script ); + + if ( ( x = fork() ) < 0 ) { + pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" ); + exit ( -3 ); + } + + if ( x == 0 ) { + execl ( b_shutdown_script, b_shutdown_script, (char*)NULL ); + pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", b_shutdown_script ); + exit ( -4 ); + } + + } + // is battery warning already active? if ( b_active ) { // warning is on! diff --git a/deployment/etc/pandora/conf/eventmap b/deployment/etc/pandora/conf/eventmap index 1025107..e897ecc 100644 --- a/deployment/etc/pandora/conf/eventmap +++ b/deployment/etc/pandora/conf/eventmap @@ -23,3 +23,5 @@ threshold 5 # in %age; at x%, we go into blink-mode as warning check_interval 300 # in seconds to check threshold; should be a high 300s blink_interval 2 # frequency of blink blink_duration 50000 # how long a blink lasts, in uSecs +shutdown_threshold 1 # battery %age we force a shutdown (to save the SD!) +shutdown_script /usr/pandora/scripts/op_shutdown.sh diff --git a/testdata/conf/eventmap b/testdata/conf/eventmap index 666a054..e9cd23f 100644 --- a/testdata/conf/eventmap +++ b/testdata/conf/eventmap @@ -19,3 +19,5 @@ threshold 5 # in %age; at x%, we go into blink-mode as warning check_interval 7 # in seconds to check threshold; should be a high 300s blink_interval 2 # frequency of blink blink_duration 50000 # how long a blink lasts, in uSecs +shutdown_threshold 1 # battery %age we force a shutdown (to save the SD!) +shutdown_script /usr/pandora/scripts/op_shutdown.sh -- 2.39.5