Fix the rfkill waiting.
This commit is contained in:
parent
56cc05599a
commit
61a48b0fb6
15
src/ndhc.c
15
src/ndhc.c
@ -485,13 +485,13 @@ static void wait_for_rfkill()
|
||||
{
|
||||
cs.rfkill_set = 1;
|
||||
struct epoll_event events[2];
|
||||
int rfkfd = rfkill_open(&client_config.enable_rfkill);
|
||||
if (rfkfd < 0)
|
||||
cs.rfkillFd = rfkill_open(&client_config.enable_rfkill);
|
||||
if (cs.rfkillFd < 0)
|
||||
suicide("can't wait for rfkill to end if /dev/rfkill can't be opened");
|
||||
int epfd = epoll_create1(0);
|
||||
if (epfd < 0)
|
||||
suicide("epoll_create1 failed");
|
||||
epoll_add(epfd, rfkfd);
|
||||
epoll_add(epfd, cs.rfkillFd);
|
||||
for (;;) {
|
||||
int r = epoll_wait(epfd, events, 2, -1);
|
||||
if (r < 0) {
|
||||
@ -502,9 +502,9 @@ static void wait_for_rfkill()
|
||||
}
|
||||
for (int i = 0; i < r; ++i) {
|
||||
int fd = events[i].data.fd;
|
||||
if (fd == rfkfd) {
|
||||
if (fd == cs.rfkillFd) {
|
||||
if (events[i].events & EPOLLIN) {
|
||||
if (!rfkill_wait_for_end(&cs, rfkfd))
|
||||
if (!rfkill_wait_for_end(&cs))
|
||||
goto rfkill_gone;
|
||||
}
|
||||
} else
|
||||
@ -513,7 +513,10 @@ static void wait_for_rfkill()
|
||||
}
|
||||
rfkill_gone:
|
||||
close(epfd);
|
||||
close(rfkfd);
|
||||
// We always close because ifchd and sockd shouldn't keep
|
||||
// an rfkill fd open.
|
||||
close(cs.rfkillFd);
|
||||
cs.rfkillFd = -1;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
18
src/rfkill.c
18
src/rfkill.c
@ -26,6 +26,7 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
@ -52,9 +53,10 @@ int rfkill_open(char enable_rfkill[static 1])
|
||||
return r;
|
||||
}
|
||||
|
||||
static int rfkill_check(struct client_state_t cs[static 1], uint32_t rfkidx,
|
||||
static int rfkill_check(struct client_state_t cs[static 1],
|
||||
int (*rfenable)(struct client_state_t[static 1]),
|
||||
int (*rfdisable)(struct client_state_t[static 1]))
|
||||
int (*rfdisable)(struct client_state_t[static 1]),
|
||||
bool check_idx, uint32_t rfkidx)
|
||||
{
|
||||
struct rfkill_event event;
|
||||
ssize_t len = safe_read(cs->rfkillFd, (char *)&event, sizeof event);
|
||||
@ -68,7 +70,7 @@ static int rfkill_check(struct client_state_t cs[static 1], uint32_t rfkidx,
|
||||
}
|
||||
log_line("rfkill: idx[%u] type[%u] op[%u] soft[%u] hard[%u]",
|
||||
event.idx, event.type, event.op, event.soft, event.hard);
|
||||
if (event.idx != rfkidx)
|
||||
if (check_idx && event.idx != rfkidx)
|
||||
return 0;
|
||||
if (event.op != RFKILL_OP_CHANGE && event.op != RFKILL_OP_CHANGE_ALL)
|
||||
return 0;
|
||||
@ -128,13 +130,13 @@ static int rfkill_wait_for_end_disable(struct client_state_t cs[static 1])
|
||||
|
||||
int handle_rfkill_notice(struct client_state_t cs[static 1], uint32_t rfkidx)
|
||||
{
|
||||
return rfkill_check(cs, rfkidx, handle_rfkill_notice_enable,
|
||||
handle_rfkill_notice_disable);
|
||||
return rfkill_check(cs, handle_rfkill_notice_enable,
|
||||
handle_rfkill_notice_disable, true, rfkidx);
|
||||
}
|
||||
|
||||
int rfkill_wait_for_end(struct client_state_t cs[static 1], uint32_t rfkidx)
|
||||
int rfkill_wait_for_end(struct client_state_t cs[static 1])
|
||||
{
|
||||
return rfkill_check(cs, rfkidx, rfkill_wait_for_end_enable,
|
||||
rfkill_wait_for_end_disable);
|
||||
return rfkill_check(cs, rfkill_wait_for_end_enable,
|
||||
rfkill_wait_for_end_disable, false, 0);
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
int rfkill_open(char enable_rfkill[static 1]);
|
||||
int handle_rfkill_notice(struct client_state_t cs[static 1], uint32_t rfkidx);
|
||||
int rfkill_wait_for_end(struct client_state_t cs[static 1], uint32_t rfkidx);
|
||||
int rfkill_wait_for_end(struct client_state_t cs[static 1]);
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user