Handle signal termination in hostapd_cli for all cases
hostapd_cli did not clean up the sockets and attachments to receive
hostapd events when SIGTERM was used to terminate it in action script
mode.
Do proper cleanup by convering the action script processing
functionality to use eloop similarly to the wpa_cli changes in commit
13f6f617ee
("wpa_cli: Fix process termination in wpa_cli action mode
case") and by registering the process termination signal handler for all
cases instead of just for the interactive mode.
Signed-off-by: Sai Pratyusha Magam <quic_smagam@quicinc.com>
This commit is contained in:
parent
d423baa42a
commit
a4af796248
1 changed files with 43 additions and 30 deletions
|
@ -314,6 +314,12 @@ static void hostapd_cli_action_process(char *msg, size_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void hostapd_cli_action_cb(char *msg, size_t len)
|
||||||
|
{
|
||||||
|
hostapd_cli_action_process(msg, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int hostapd_cli_cmd_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
|
static int hostapd_cli_cmd_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char buf[64];
|
char buf[64];
|
||||||
|
@ -2033,7 +2039,6 @@ static void hostapd_cli_interactive(void)
|
||||||
os_snprintf(hfile, hfile_len, "%s/%s", home, fname);
|
os_snprintf(hfile, hfile_len, "%s/%s", home, fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
eloop_register_signal_terminate(hostapd_cli_eloop_terminate, NULL);
|
|
||||||
edit_init(hostapd_cli_edit_cmd_cb, hostapd_cli_edit_eof_cb,
|
edit_init(hostapd_cli_edit_cmd_cb, hostapd_cli_edit_eof_cb,
|
||||||
hostapd_cli_edit_completion_cb, NULL, hfile, NULL);
|
hostapd_cli_edit_completion_cb, NULL, hfile, NULL);
|
||||||
eloop_register_timeout(ping_interval, 0, hostapd_cli_ping, NULL, NULL);
|
eloop_register_timeout(ping_interval, 0, hostapd_cli_ping, NULL, NULL);
|
||||||
|
@ -2057,40 +2062,46 @@ static void hostapd_cli_cleanup(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void hostapd_cli_action(struct wpa_ctrl *ctrl)
|
static void hostapd_cli_action_ping(void *eloop_ctx, void *timeout_ctx)
|
||||||
{
|
{
|
||||||
fd_set rfds;
|
struct wpa_ctrl *ctrl = eloop_ctx;
|
||||||
int fd, res;
|
|
||||||
struct timeval tv;
|
|
||||||
char buf[256];
|
char buf[256];
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
fd = wpa_ctrl_get_fd(ctrl);
|
/* verify that connection is still working */
|
||||||
|
|
||||||
while (!hostapd_cli_quit) {
|
|
||||||
FD_ZERO(&rfds);
|
|
||||||
FD_SET(fd, &rfds);
|
|
||||||
tv.tv_sec = ping_interval;
|
|
||||||
tv.tv_usec = 0;
|
|
||||||
res = select(fd + 1, &rfds, NULL, NULL, &tv);
|
|
||||||
if (res < 0 && errno != EINTR) {
|
|
||||||
perror("select");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FD_ISSET(fd, &rfds))
|
|
||||||
hostapd_cli_recv_pending(ctrl, 0, 1);
|
|
||||||
else {
|
|
||||||
len = sizeof(buf) - 1;
|
len = sizeof(buf) - 1;
|
||||||
if (wpa_ctrl_request(ctrl, "PING", 4, buf, &len,
|
if (wpa_ctrl_request(ctrl, "PING", 4, buf, &len,
|
||||||
hostapd_cli_action_process) < 0 ||
|
hostapd_cli_action_cb) < 0 ||
|
||||||
len < 4 || os_memcmp(buf, "PONG", 4) != 0) {
|
len < 4 || os_memcmp(buf, "PONG", 4) != 0) {
|
||||||
printf("hostapd did not reply to PING "
|
printf("hostapd did not reply to PING command - exiting\n");
|
||||||
"command - exiting\n");
|
eloop_terminate();
|
||||||
break;
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
eloop_register_timeout(ping_interval, 0, hostapd_cli_action_ping,
|
||||||
|
ctrl, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void hostapd_cli_action_receive(int sock, void *eloop_ctx,
|
||||||
|
void *sock_ctx)
|
||||||
|
{
|
||||||
|
struct wpa_ctrl *ctrl = eloop_ctx;
|
||||||
|
|
||||||
|
hostapd_cli_recv_pending(ctrl, 0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void hostapd_cli_action(struct wpa_ctrl *ctrl)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
fd = wpa_ctrl_get_fd(ctrl);
|
||||||
|
eloop_register_timeout(ping_interval, 0, hostapd_cli_action_ping,
|
||||||
|
ctrl, NULL);
|
||||||
|
eloop_register_read_sock(fd, hostapd_cli_action_receive, ctrl, NULL);
|
||||||
|
eloop_run();
|
||||||
|
eloop_cancel_timeout(hostapd_cli_action_ping, ctrl, NULL);
|
||||||
|
eloop_unregister_read_sock(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2193,6 +2204,8 @@ int main(int argc, char *argv[])
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eloop_register_signal_terminate(hostapd_cli_eloop_terminate, NULL);
|
||||||
|
|
||||||
if (action_file && !hostapd_cli_attached)
|
if (action_file && !hostapd_cli_attached)
|
||||||
return -1;
|
return -1;
|
||||||
if (daemonize && os_daemonize(pid_file) && eloop_sock_requeue())
|
if (daemonize && os_daemonize(pid_file) && eloop_sock_requeue())
|
||||||
|
|
Loading…
Reference in a new issue