Check .pid file regularly instead of waiting a second blindly. Saves up to a second of wall time per call. --- src/8021x | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/8021x b/src/8021x index d143b30..7af6950 100644 --- a/src/8021x +++ b/src/8021x @@ -38,21 +38,21 @@ start_wpa() fi wpa_supplicant -B -P "/run/wpa_supplicant_${INTERFACE}.pid" -i "$INTERFACE" -D "$WPA_DRIVER" "$WPA_CONF" $WPA_OPTS - sleep 1 - if [[ ! -f "/run/wpa_supplicant_${INTERFACE}.pid" ]]; then - return 1 - fi + # wait up to one second until pid file appears + timeout_wait 1 "[[ -f \"/run/wpa_supplicant_${INTERFACE}.pid\" ]]"; + return $? } stop_wpa() { wpa_cli -p "$WPA_CTRL_PATH" -i "$1" terminate &> /dev/null - sleep 1 # JP: need this else the file tends to disappear after [[ -f ... ]] but before cat... - # see <http://bbs.archlinux.org/viewtopic.php?pid=515667#p515667> - if [[ -f "/run/wpa_supplicant_$1.pid" ]]; then + + # sleep up to one second, waiting for pid file to be removed + # JP: need to sleep else the file tends to disappear after [[ -f ... ]] but before cat... + # see <http://bbs.archlinux.org/viewtopic.php?pid=515667#p515667> + timeout_wait 1 "[[ ! -f \"/run/wpa_supplicant_$1.pid\" ]]" || \ kill "$(< "/run/wpa_supplicant_$1.pid")" &>/dev/null & - fi } wpa_reconfigure() { -- 1.7.11.1