From f9421496842759b779140831fc6347ccc2341c91 Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Fri, 23 Jul 2021 05:57:43 -0400 Subject: [PATCH] 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 --- src/common/wpa_ctrl.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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);