about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSören Tempel <soeren+git@soeren-tempel.net>2015-03-31 15:54:08 +0200
committerSören Tempel <soeren+git@soeren-tempel.net>2015-03-31 16:52:28 +0200
commitaf68d02c0d3c576a874137e34abbe29e1ecc4c6f (patch)
treea54ef41435e43be2f7e8029e84eadf97e6bc9d05
parent6e03320cd69e3b9bb7647d3113d2684d3137b4cc (diff)
downloadrunit-void-af68d02c0d3c576a874137e34abbe29e1ecc4c6f.tar.gz
runit-void-af68d02c0d3c576a874137e34abbe29e1ecc4c6f.tar.xz
runit-void-af68d02c0d3c576a874137e34abbe29e1ecc4c6f.zip
shutdown: add abort helper function
-rwxr-xr-xshutdown16
1 files changed, 10 insertions, 6 deletions
diff --git a/shutdown b/shutdown
index 7fe26ae..448e6d5 100755
--- a/shutdown
+++ b/shutdown
@@ -5,15 +5,20 @@ single() {
   runsvchdir single
 }
 
+abort() {
+  echo "$@" >&2
+  exit 1
+}
+
 usage() {
-  echo "Usage: shutdown [-fF] [-kchPr] time [warning message]" >&2; exit 1
+  abort "Usage: shutdown [-fF] [-kchPr] time [warning message]"
 }
 
 action=single
 
 while getopts akrhPHfFnct: opt; do
   case "$opt" in
-    a|n|H) echo "-$opt is not implemented" >&2; exit 1;;
+    a|n|H) abort "-$opt is not implemented";;
     t) ;;
     f) touch /fastboot;;
     F) touch /forcefsck;;
@@ -38,16 +43,15 @@ if [ "$action" = "cancel" ]; then
 fi
 
 if ! touch /run/runit/shutdown.pid 2>/dev/null; then
-  echo "Not enough permissions to execute ${0#*/}"
-  exit 1
+  abort "Not enough permissions to execute ${0#*/}"
 fi
 echo $$ >/run/runit/shutdown.pid
 
 case "$time" in
   now) time=0;;
   +*) time=${time#+};;
-  *:*) echo "absolute time is not implemented" >&2; exit 1;;
-  *) echo "invalid time"; exit 1;;
+  *:*) abort "absolute time is not implemented";;
+  *) abort "invalid time";;
 esac
 
 if [ "$time" -gt 5 ]; then