[PATCH] supplicant: Make unix socket non-blocking.

Jouni Malinen j at w1.fi
Sun Feb 5 12:18:29 EST 2012


On Thu, Jan 05, 2012 at 10:52:46AM -0800, greearb at candelatech.com wrote:
> This keeps wpa_cli from hanging forever if the other end of the
> socket dies.

Hmm.. The change here is for wpa_cli:

> diff --git a/src/common/wpa_ctrl.c b/src/common/wpa_ctrl.c
> @@ -321,7 +322,29 @@ int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len,
> +retry_send:
>  	if (send(ctrl->s, _cmd, _cmd_len, 0) < 0) {
> +		if ((errno == EAGAIN) || (errno = EBUSY)
> +		    || (errno == EWOULDBLOCK)) {
> +			/* Must be non-blocking socket...try for a bit longer
> +			 * before giving up.
> +			 */

...

while the part that makes the socket non-blocking is for wpa_supplicant:

> diff --git a/wpa_supplicant/ctrl_iface_unix.c b/wpa_supplicant/ctrl_iface_unix.c
> @@ -411,6 +413,17 @@ wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
> +	/* Make socket non-blocking so that we don't hang forever if
> +	 * target dies unexpectedly.
> +	 */
> +	flags = fcntl(priv->sock, F_GETFL);
> +	flags |= (O_NONBLOCK);
> +	if (fcntl(priv->sock, F_SETFL, flags) < 0) {

Am I missing something here or how is this supposed to work? Shouldn't
these changes be for the same socket, i.e., the one used by wpa_cli, or
were you thinking of making both wpa_cli and wpa_supplicant use
non-blocking sockets (in which case this fnctl call would need to be in
wpa_ctrl.c, too, I'd assume)?
 
-- 
Jouni Malinen                                            PGP id EFC895FA


More information about the HostAP mailing list