wpa_cli: Fix process termination in wpa_cli action mode case

Commit 4be9f27595 ('wpa_cli: Use eloop
during connection attempts in interactive mode') did not take into
account the needs for signal processing in action mode. eloop_run() was
not called in this case and the internal select() loop would block eloop
processing anyway and prevent clean shutdown. Fix this by using eloop
for action mode operations.

Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
This commit is contained in:
Jouni Malinen 2015-06-18 13:48:21 +03:00 committed by Jouni Malinen
parent b4c0f58452
commit 13f6f617ee

View file

@ -4099,45 +4099,49 @@ static void wpa_cli_interactive(void)
} }
static void wpa_cli_action_ping(void *eloop_ctx, void *timeout_ctx)
{
struct wpa_ctrl *ctrl = eloop_ctx;
char buf[256];
size_t len;
/* verify that connection is still working */
len = sizeof(buf) - 1;
if (wpa_ctrl_request(ctrl, "PING", 4, buf, &len,
wpa_cli_action_cb) < 0 ||
len < 4 || os_memcmp(buf, "PONG", 4) != 0) {
printf("wpa_supplicant did not reply to PING command - exiting\n");
eloop_terminate();
return;
}
eloop_register_timeout(ping_interval, 0, wpa_cli_action_ping,
ctrl, NULL);
}
static void wpa_cli_action_receive(int sock, void *eloop_ctx, void *sock_ctx)
{
struct wpa_ctrl *ctrl = eloop_ctx;
wpa_cli_recv_pending(ctrl, 1);
}
static void wpa_cli_action(struct wpa_ctrl *ctrl) static void wpa_cli_action(struct wpa_ctrl *ctrl)
{ {
#ifdef CONFIG_ANSI_C_EXTRA #ifdef CONFIG_ANSI_C_EXTRA
/* TODO: ANSI C version(?) */ /* TODO: ANSI C version(?) */
printf("Action processing not supported in ANSI C build.\n"); printf("Action processing not supported in ANSI C build.\n");
#else /* CONFIG_ANSI_C_EXTRA */ #else /* CONFIG_ANSI_C_EXTRA */
fd_set rfds; int fd;
int fd, res;
struct timeval tv;
char buf[256]; /* note: large enough to fit in unsolicited messages */
size_t len;
fd = wpa_ctrl_get_fd(ctrl); fd = wpa_ctrl_get_fd(ctrl);
eloop_register_timeout(ping_interval, 0, wpa_cli_action_ping,
while (!wpa_cli_quit) { ctrl, NULL);
FD_ZERO(&rfds); eloop_register_read_sock(fd, wpa_cli_action_receive, ctrl, NULL);
FD_SET(fd, &rfds); eloop_run();
tv.tv_sec = ping_interval; eloop_cancel_timeout(wpa_cli_action_ping, ctrl, NULL);
tv.tv_usec = 0; eloop_unregister_read_sock(fd);
res = select(fd + 1, &rfds, NULL, NULL, &tv);
if (res < 0 && errno != EINTR) {
perror("select");
break;
}
if (FD_ISSET(fd, &rfds))
wpa_cli_recv_pending(ctrl, 1);
else {
/* verify that connection is still working */
len = sizeof(buf) - 1;
if (wpa_ctrl_request(ctrl, "PING", 4, buf, &len,
wpa_cli_action_cb) < 0 ||
len < 4 || os_memcmp(buf, "PONG", 4) != 0) {
printf("wpa_supplicant did not reply to PING "
"command - exiting\n");
break;
}
}
}
#endif /* CONFIG_ANSI_C_EXTRA */ #endif /* CONFIG_ANSI_C_EXTRA */
} }