Added critical battery level forced shutdown .. calls script when battery gets to...
authorskeezix <skeezix@flotsam-vm.(none)>
Thu, 18 Feb 2010 03:26:04 +0000 (22:26 -0500)
committerskeezix <skeezix@flotsam-vm.(none)>
Thu, 18 Feb 2010 03:26:04 +0000 (22:26 -0500)
configured in evmapper conf

apps/pndevmapperd.c
deployment/etc/pandora/conf/eventmap
testdata/conf/eventmap

index f09cbfe..713b819 100644 (file)
@@ -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!
index 1025107..e897ecc 100644 (file)
@@ -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
index 666a054..e9cd23f 100644 (file)
@@ -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