X-Git-Url: https://git.decadent.org.uk/gitweb/?p=odhcp6c.git;a=blobdiff_plain;f=odhcp6c-example-script.sh;h=00d80560c1a015c967f7bf77eec9081c47a3cfca;hp=621525750bcdfaeb22244350643b6007265cc06c;hb=b5f6ace7148fda6bf336758d2544a23a90d845bf;hpb=b4a0f3d74b04074eae21e88fbf5b8f2ddc150f86 diff --git a/odhcp6c-example-script.sh b/odhcp6c-example-script.sh index 6215257..00d8056 100755 --- a/odhcp6c-example-script.sh +++ b/odhcp6c-example-script.sh @@ -6,12 +6,13 @@ update_resolv() { local dns="$2" ( - flock -n 9 + flock 9 grep -v "#odhcp6c:$device:" /etc/resolv.conf > /tmp/resolv.conf.tmp for c in $dns; do echo "nameserver $c #odhcp6c:$device:" >> /tmp/resolv.conf.tmp done mv /tmp/resolv.conf.tmp /etc/resolv.conf + chmod 0644 /etc/resolv.conf ) 9>/tmp/resolv.conf.lock rm -f /tmp/resolv.conf.lock /tmp/resolv.conf.tmp } @@ -131,23 +132,25 @@ teardown_interface() { update_resolv "$device" "" } -case "$2" in - bound) - teardown_interface "$1" - setup_interface "$1" - ;; - informed|updated|rebound|ra-updated) - setup_interface "$1" - ;; - stopped|unbound) - teardown_interface "$1" - ;; - started) - teardown_interface "$1" - ;; -esac - -# user rules -[ -f /etc/odhcp6c.user ] && . /etc/odhcp6c.user - -exit 0 +( + flock 9 + case "$2" in + bound) + teardown_interface "$1" + setup_interface "$1" + ;; + informed|updated|rebound|ra-updated) + setup_interface "$1" + ;; + stopped|unbound) + teardown_interface "$1" + ;; + started) + teardown_interface "$1" + ;; + esac + + # user rules + [ -f /etc/odhcp6c.user ] && . /etc/odhcp6c.user +) 9>/tmp/odhcp6c.lock.$1 +rm -f /tmp/odhcp6c.lock.$1