Here’s a rewritten script in modern, robust POSIX sh and Debian style:

#!/bin/sh

set -e

test -n "$IF_TINC_NET" || exit 0

test -e "/var/run/tinc.$IF_TINC_NET.pid" || exit 0
read pid rest <"/var/run/tinc.$IF_TINC_NET.pid"
case $pid in
(*[^0-9]*)
        echo >&2 "E: PID '$pid' of tinc daemon not numeric!"
        exit 1
        ;;
esac

i=0
while test $i -lt 30; do
        kill -0 "$pid" 2>/dev/null || exit 0
        $(which sleep) 0.1
        i=$(($i + 1))
done
echo >&2 'E: failed to stop tinc daemon!'
exit 1


Of course, deal with a nonexistent file as you prefer.

Enjoy
//mirabilos
-- 
Yay for having to rewrite other people's Bash scripts because bash
suddenly stopped supporting the bash extensions they make use of
        -- Tonnerre Lombard in #nosec

Reply via email to