[arch-projects] [netcfg] [PATCH 4/4] Wait actively in {start, stop}_wpa

Jouke Witteveen j.witteveen at gmail.com
Mon Jul 2 19:25:48 EDT 2012


On Mon, Jul 2, 2012 at 11:07 PM, Henrik Hallberg <henrik at k2h.se> wrote:
> Check .pid file regularly instead of waiting a second blindly. Saves up
> to a second of wall time per call.
> ---
>  src/8021x | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/src/8021x b/src/8021x
> index d143b30..b78dcf9 100644
> --- a/src/8021x
> +++ b/src/8021x
> @@ -38,18 +38,23 @@ 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 success if pid file exists, else failure

I would ditch the above two lines (a bit superfluous).

> +    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>
> +
> +    # 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\" ]]"
> +
>      if [[ -f "/run/wpa_supplicant_$1.pid" ]]; then
>          kill "$(< "/run/wpa_supplicant_$1.pid")" &>/dev/null &
>      fi

This can be merged like:
timeout_wait 1 '[[ ! -f "/run/wpa_supplicant_$1.pid" ]]' || kill "$(<
"/run/wpa_supplicant_$1.pid")" &>/dev/null &

> --
> 1.7.11.1
>

If these changes save 4 seconds, I guess the supplicant is stopped
more than necessary. I'd say: if you're gonna need it, start it once
(and once only)! I haven't investigated this.

Regards,
- Jouke


More information about the arch-projects mailing list