diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-10-26 00:40:58 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-10-26 00:40:58 -0400 |
commit | 66e08077bee03c33b13064b892171bf6e1c320e3 (patch) | |
tree | dfc2303df321860a5e5d0e0150148428c97d2bfb | |
parent | 69573b173f10fa315aa3ce8c4af67fce2a31f60b (diff) |
tidy
-rw-r--r-- | Makefile | 4 | ||||
-rwxr-xr-x | netctl-hook | 2 | ||||
-rwxr-xr-x | network-online | 25 |
3 files changed, 23 insertions, 8 deletions
@@ -8,10 +8,11 @@ install-targets = \ $(DESTDIR)/lib/systemd/system/network-online@.service \ $(DESTDIR)/lib/network/network-online +all: install: $(install-targets) uninstall: rm -f -- $(install-targets) -.PHONY: install uninstall +.PHONY: all install uninstall $(DESTDIR)/etc/netctl/hooks/network-online: netctl-hook install -Dm755 $< $@ @@ -19,4 +20,3 @@ $(DESTDIR)/lib/systemd/system/network-online@.service: network-online@.service install -Dm644 $< $@ $(DESTDIR)/lib/network/network-online: network-online install -Dm755 $< $@ - diff --git a/netctl-hook b/netctl-hook index 5190f02..01f8619 100755 --- a/netctl-hook +++ b/netctl-hook @@ -1,3 +1,3 @@ -#!/hint/sh +#!/hint/bash printf -v ExecUpPost "systemctl start network-online@%q.service" "$(systemd-escape -- "$Profile")" printf -v ExecDownPre "systemctl stop network-online@%q.service" "$(systemd-escape -- "$Profile")" diff --git a/network-online b/network-online index 5bb51d8..484567b 100755 --- a/network-online +++ b/network-online @@ -4,10 +4,24 @@ # terms of the Do What The Fuck You Want To Public License, Version 2, # as published by Sam Hocevar. See the COPYING file for more details. +# Usage: network-online [start|stop] NETWORK_NAME mode="$1" lock=/run/network-online/lock fifo=/run/network-online/"$2" PS4="$mode: " + +# Use a named pipe (fifo) as an inter-process synchronization +# mechanism; a call to block_{a,b} blocks its counterpart is run. +block_a() { + cat "$fifo" >/dev/null +} +block_b() { + echo foo >> "$fifo" +} + +# Because of restrictions put in place by systemd, the ExecStart +# process can't run `systemctl stop network-online.target`, but the +# ExecStop process can. case "$mode" in start) trap 'rm -f -- "$fifo"' EXIT @@ -16,17 +30,18 @@ case "$mode" in exec 8>"$lock" || exit $? flock -s 8 || exit $? systemctl start network-online.target || exit $? - mkfifo "$fifo" || exit $? - cat "$fifo" + + block_a # wait for 'stop' to be called exec 8>&- - echo stopped >> "$fifo" + block_a # signal to 'stop' that we've unlocked ;; stop) set -x exec 8>"$lock" || exit $? - echo stopping >> "$fifo" || exit $? - cat "$fifo" || exit $? + flock -s 8 || exit $? + block_b # signal 'start' to stop + block_b # wait for 'start' to unlock if flock -x -n 8; then systemctl stop network-online.target rm -rf /run/network-online |