Fix the rfkill waiting.

This commit is contained in:
Nicholas J. Kain
2015-02-14 15:33:02 -05:00
parent 56cc05599a
commit 61a48b0fb6
3 changed files with 21 additions and 16 deletions

View File

@ -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[])