fff-vpn-select: improve logic for fastd start/stop #13
No reviewers
Labels
No Label
RFC
RFT
WIP
blocked
bsp
bug
build/scripts/tools
duplicate
feature
fixed
layer3
mantis
more details required
needs changes
node
packages/fff
rejected
security
trivial
upstream
No Milestone
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: freifunk-franken/firmware#13
Loading…
Reference in New Issue
No description provided.
Delete Branch "adschm/firmware:vpnlogic"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The start/stop part of fff-vpn-select currently uses a subshell
for what is meant to be logic grouping. Address that by swapping
condition levels and add comment to explain what is actually done.
@ -54,3 +54,2 @@
pidfile="/tmp/run/fastd.fff.pid"
if [ "$(ls /etc/fastd/fff/peers/* 2>/dev/null)" ]; then
([ -s "$pidfile" ] && [ -d "/proc/$(cat "$pidfile")" ]) || /etc/init.d/fastd start
if [ -s "$pidfile" ] && [ -d "/proc/$(cat "$pidfile")" ]; then
[ -s "$pidfile" ] && [ -d "/proc/$(cat "$pidfile")" ]
sollte aequivalent zu[ -s "$pidfile" -a -d "/proc/$(cat "$pidfile")" ]
sein und spart einen aufruf an testshellcheck sagt "Prefer [ p ] && [ q ] as [ p -a q ] is not well defined."
@ -56,1 +55,3 @@
([ -s "$pidfile" ] && [ -d "/proc/$(cat "$pidfile")" ]) || /etc/init.d/fastd start
if [ -s "$pidfile" ] && [ -d "/proc/$(cat "$pidfile")" ]; then
# Stop if service is running but no peers present
[ "$(ls /etc/fastd/fff/peers/* 2>/dev/null)" ] || /etc/init.d/fastd stop
Gibt es einen Grund
[ "$(ls /etc/fastd/fff/peers/* 2>/dev/null)" ] || ...
statt einfach direkt
ls /etc/fastd/fff/peers/* 2>/dev/null || ...
zu nutzen?
Ich fand das auch ekelig, habe dann gegoogled und tatsächlich wird genau das bestehende als Optimum empfohlen. Bei ls ohne [] muss man ja noch den Output unterdrücken ... Außerdem bin ich mir nicht sicher, wie ls mit return values umgeht, wenn man wildcards verwendet ...
ls /etc/fastd/fff/peers/* &>/dev/null || ...
scheint zu funktionieren, aber ob das jetzt besser ist?
also
$(...)
wuerde meines wissens eine neue subshell aufmachen. Die wuerden wir uns mit dem Ansatz sparen.Die Sach ist ganz simpel. ls wirft bei einem leeren Verzeichnis keinen Fehler. Mit * hinten dran bekommen wir den Fehler weil das globbing nicht funzt. D.h. nicht unbedingt, dass das Verzeichnis leer ist. Darum der Test auf "leere" Ausgabe von ls.
In unserem Fall koennte es sogar besser sein, den * wegzulassen.
2fb746fe4c
todadde41b3c
Pull request closed