From: Natanael Copa Date: Thu, 27 Dec 2012 08:52:30 +0000 (+0100) Subject: lxc-shutdown: use posix shell instead of bash X-Git-Tag: lxc-0.9.0.alpha3~1^2~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=600faead3804e7f507e18bdb41588964b0fc611f;p=thirdparty%2Flxc.git lxc-shutdown: use posix shell instead of bash - avoid getopt --longoptions - use 'which' instead of 'type' to detect existance of tools - specify -s SIG with kill Signed-off-by: Natanael Copa Acked-by: Stéphane Graber --- diff --git a/src/lxc/lxc-shutdown.in b/src/lxc/lxc-shutdown.in index f30e22b86..ad8395be7 100644 --- a/src/lxc/lxc-shutdown.in +++ b/src/lxc/lxc-shutdown.in @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # (C) Copyright Canonical 2011,2012 @@ -41,30 +41,30 @@ dolxcstop() exit 0 } -shortoptions='hn:rwt:' -longoptions='help,name:,wait,reboot,timeout:' - -timeout="-1" - -getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@") -if [ $? != 0 ]; then +usage_err() { + [ -n "$1" ] && echo "$1" >&2 usage - exit 1; -fi + exit 1 +} + +optarg_check() { + [ -n "$2" ] || usage_err "option '$1' requires an argument" +} -eval set -- "$getopt" +timeout="-1" reboot=0 dowait=0 -while true; do - case "$1" in +while [ $# -gt 0 ]; do + opt="$1" + shift + case "$opt" in -h|--help) usage - exit 1 ;; -n|--name) - shift + optarg_check $opt "$1" lxc_name=$1 shift ;; @@ -77,19 +77,23 @@ while true; do shift ;; -t|--timeout) - shift + optarg_check $opt "$1" timeout=$1 dowait=1 shift ;; --) - shift break;; + -?) + usage_err "unknown option '$opt'" + ;; + -*) + # split opts -abc into -a -b -c + set -- $(echo "${opt#-}" | sed 's/\(.\)/ -\1/g') "$@" + ;; *) - echo $1 - usage + usage_err "unknown option '$opt'" exit 1 - ;; esac done @@ -104,8 +108,8 @@ if [ "$(id -u)" != "0" ]; then exit 1 fi -type lxc-info > /dev/null || { echo "lxc-info not found."; exit 1; } -type lxc-wait > /dev/null || { echo "lxc-wait not found."; exit 1; } +which lxc-info > /dev/null || { echo "lxc-info not found."; exit 1; } +which lxc-wait > /dev/null || { echo "lxc-wait not found."; exit 1; } pid=`lxc-info -n $lxc_name -p 2>/dev/null | awk '{ print $2 }'` if [ "$pid" = "-1" ]; then @@ -114,10 +118,10 @@ if [ "$pid" = "-1" ]; then fi if [ $reboot -eq 1 ]; then - kill -INT $pid + kill -s SIGINT $pid exit 0 else - kill -PWR $pid + kill -s SIGPWR $pid fi if [ $dowait -eq 0 ]; then