From: Alan T. DeKok Date: Fri, 23 Jul 2021 09:57:43 +0000 (-0400) Subject: wpa_ctrl: Wait for a total of 10 seconds, not 10 seconds per iteration X-Git-Tag: hostap_2_11~2023 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9421496842759b779140831fc6347ccc2341c91;p=thirdparty%2Fhostap.git wpa_ctrl: Wait for a total of 10 seconds, not 10 seconds per iteration EINTR will cause the loop to restart, which means that the total time could be significantly longer than 10 seconds. Signed-off-by: Alan DeKok --- diff --git a/src/common/wpa_ctrl.c b/src/common/wpa_ctrl.c index 40a979531..7e197f094 100644 --- a/src/common/wpa_ctrl.c +++ b/src/common/wpa_ctrl.c @@ -483,7 +483,7 @@ int wpa_ctrl_request(struct wpa_ctrl *ctrl, const char *cmd, size_t cmd_len, void (*msg_cb)(char *msg, size_t len)) { struct timeval tv; - struct os_reltime started_at; + struct os_reltime started_at, ending_at; int res; fd_set rfds; const char *_cmd; @@ -539,9 +539,19 @@ retry_send: } os_free(cmd_buf); + os_get_reltime(&ending_at); + ending_at.sec += 10; + for (;;) { - tv.tv_sec = 10; - tv.tv_usec = 0; + struct os_reltime diff; + + os_get_reltime(&started_at); + if (os_reltime_before(&ending_at, &started_at)) + return -2; + os_reltime_sub(&ending_at, &started_at, &diff); + tv.tv_sec = diff.sec; + tv.tv_usec = diff.usec; + FD_ZERO(&rfds); FD_SET(ctrl->s, &rfds); res = select(ctrl->s + 1, &rfds, NULL, NULL, &tv);