[PATCH] Handle EAGAIN in wpa_supplicant_ctrl_iface_send

Ben Greear greearb
Fri Sep 20 09:05:41 PDT 2013


On 09/20/2013 12:53 AM, Pontus Fuchs wrote:
> Commit 4fdc8def changed the ctrl interface socket to be non-blocking,
> but didn't update wpa_supplicant_ctrl_iface_send to handle EAGAIN.
>
> If a burst of events are sent, the socket queue can overflow and
> sendmsg fails with EAGAIN. When this happens the monitor is silently
> detached.

Patch looks OK to me, but since sendmsg uses MSG_DONTWAIT, then it
was always non-blocking and my patch should have not made things any
worse...

Thanks,
Ben

>
> Signed-hostap: Pontus Fuchs <pontus.fuchs at gmail.com>
> ---
>   wpa_supplicant/ctrl_iface_unix.c | 15 +++++++++++----
>   1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/wpa_supplicant/ctrl_iface_unix.c b/wpa_supplicant/ctrl_iface_unix.c
> index 49489d6..2c67b9c 100644
> --- a/wpa_supplicant/ctrl_iface_unix.c
> +++ b/wpa_supplicant/ctrl_iface_unix.c
> @@ -623,14 +623,21 @@ static void wpa_supplicant_ctrl_iface_send(const char *ifname, int sock,
>   			msg.msg_name = (void *) &dst->addr;
>   			msg.msg_namelen = dst->addrlen;
>   			if (sendmsg(sock, &msg, MSG_DONTWAIT) < 0) {
> -				int _errno = errno;
> +				int _errno = errno, detach = 0;
>   				wpa_printf(MSG_INFO, "CTRL_IFACE monitor[%d]: "
>   					   "%d - %s",
>   					   idx, errno, strerror(errno));
>   				dst->errors++;
> -				if (dst->errors > 1000 ||
> -				    (_errno != ENOBUFS && dst->errors > 10) ||
> -				    _errno == ENOENT) {
> +				if (dst->errors > 1000 || _errno == ENOENT)
> +					detach = 1;
> +				if (!(_errno == ENOBUFS || _errno == EAGAIN ||
> +				    _errno == EWOULDBLOCK) && dst->errors > 10)
> +					detach = 1;
> +				if (detach) {
> +					wpa_printf(MSG_ERROR, "CTRL_IFACE "
> +						   "monitor[%d]: Too many "
> +						   "errors. Detaching. ",
> +						   idx);
>   					wpa_supplicant_ctrl_iface_detach(
>   						ctrl_dst, &dst->addr,
>   						dst->addrlen);
>


-- 
Ben Greear <greearb at candelatech.com>
Candela Technologies Inc  http://www.candelatech.com




More information about the Hostap mailing list