summaryrefslogtreecommitdiff
path: root/recipes-core/multitech/reset-handler
diff options
context:
space:
mode:
authorJesse Gilles <jgilles@multitech.com>2014-11-04 11:51:34 -0600
committerJesse Gilles <jgilles@multitech.com>2014-11-04 11:51:34 -0600
commite243c30f04c18722dc65effe6d4f275a3f35de46 (patch)
tree807610ce8af0ead02681d6c3cc89d902ec941652 /recipes-core/multitech/reset-handler
downloadmeta-mlinux-e243c30f04c18722dc65effe6d4f275a3f35de46.tar.gz
meta-mlinux-e243c30f04c18722dc65effe6d4f275a3f35de46.tar.bz2
meta-mlinux-e243c30f04c18722dc65effe6d4f275a3f35de46.zip
initial commit of mLinux layer
Diffstat (limited to 'recipes-core/multitech/reset-handler')
-rw-r--r--recipes-core/multitech/reset-handler/reset-handler.default2
-rw-r--r--recipes-core/multitech/reset-handler/reset-handler.init30
-rwxr-xr-xrecipes-core/multitech/reset-handler/reset-handler.sh72
3 files changed, 104 insertions, 0 deletions
diff --git a/recipes-core/multitech/reset-handler/reset-handler.default b/recipes-core/multitech/reset-handler/reset-handler.default
new file mode 100644
index 0000000..71b3e24
--- /dev/null
+++ b/recipes-core/multitech/reset-handler/reset-handler.default
@@ -0,0 +1,2 @@
+# set to "no" to disable reset-handler starting on boot
+ENABLED="yes"
diff --git a/recipes-core/multitech/reset-handler/reset-handler.init b/recipes-core/multitech/reset-handler/reset-handler.init
new file mode 100644
index 0000000..b50e7b8
--- /dev/null
+++ b/recipes-core/multitech/reset-handler/reset-handler.init
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+DAEMON=/usr/sbin/reset-handler
+PIDFILE=/var/run/reset-handler.pid
+ENABLED="yes"
+
+[ -r /etc/default/reset-handler ] && . /etc/default/reset-handler
+[ -x $DAEMON ] || exit 0
+[ "$ENABLED" = "yes" ] || exit 0
+
+case "$1" in
+ start)
+ if [ -f $PIDFILE ]; then
+ echo "reset-handler pid file exists, not starting"
+ exit 1
+ else
+ echo "Starting reset-handler"
+ start-stop-daemon --start --background --make-pidfile --pidfile $PIDFILE --exec $DAEMON
+ fi
+ ;;
+ stop)
+ echo "Stopping reset-handler"
+ start-stop-daemon --stop --oknodo --pidfile $PIDFILE
+ rm -f $PIDFILE
+ ;;
+ *)
+ echo "Usage: $0 {start|stop}"
+ exit 2
+ ;;
+esac
diff --git a/recipes-core/multitech/reset-handler/reset-handler.sh b/recipes-core/multitech/reset-handler/reset-handler.sh
new file mode 100755
index 0000000..62eeda8
--- /dev/null
+++ b/recipes-core/multitech/reset-handler/reset-handler.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+
+# Copyright (C) 2014 Multi-Tech Systems
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+name="reset-handler"
+log="logger -t $name -s"
+pid="$$"
+
+short_signal=10 # SIGUSR1
+long_signal=12 # SIGUSR2
+extralong_signal=1 # SIGHUP
+
+do_reboot() {
+ $log "Rebooting on button press"
+ sleep 1
+ reboot
+}
+
+do_restore_defaults() {
+ $log "Setting restore defaults on reboot"
+ touch /var/config/force_defaults
+ $log "Rebooting"
+ sleep 1
+ reboot
+}
+
+log_exit() {
+ $log "Exiting on SIGTERM"
+ exit 0
+}
+
+idle_wait() {
+ pipe=/var/tmp/$name.fifo
+ rm -f $pipe
+ mkfifo -m 400 $pipe
+
+ # sneaky way to do nothing forever
+ while true; do
+ read < $pipe
+ done
+}
+
+trap do_reboot $short_signal
+trap do_restore_defaults $long_signal
+trap do_restore_defaults $extralong_signal
+trap log_exit TERM
+
+$log "Enabling reset-monitor for pid $pid"
+mts-io-sysfs store reset-monitor "$pid $short_signal $long_signal $extralong_signal"
+# set long press to 5 seconds for reset to defaults
+mts-io-sysfs store reset-monitor-intervals "5 30"
+
+# wait for signals
+idle_wait