From 384c6f27bb91b332c263de25a0a510507ed523a9 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Mon, 19 Oct 2015 08:31:50 +0000 Subject: nlplug-findfs: wait indefinitively til trigger thread is complete make sure that we dont exit before the trigger thread is complete, regardless if we find the devices/bootrepo/apkovl we are looking for or not. --- nlplug-findfs.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'nlplug-findfs.c') diff --git a/nlplug-findfs.c b/nlplug-findfs.c index ceaafab..4687c66 100644 --- a/nlplug-findfs.c +++ b/nlplug-findfs.c @@ -300,7 +300,7 @@ void recurse_dir(char *pathbuf, struct recurse_opts *opts) goto next; } is_dir = S_ISDIR(st.st_mode); - else + } else is_dir = entry->d_type & DT_DIR; if (is_dir) { @@ -636,7 +636,7 @@ int main(int argc, char *argv[]) struct ueventconf conf; int event_count = 0; size_t total_bytes; - int found = 0; + int found = 0, trigger_running = 0; char *program_argv[2] = {0,0}; pthread_t tid; @@ -691,8 +691,9 @@ int main(int argc, char *argv[]) fds[1].events = POLLIN; pthread_create(&tid, NULL, trigger_thread, &fds[1].fd); + trigger_running = 1; - while ((r = poll(fds, numfds, conf.timeout)) > 0 || numfds > 1) { + while (trigger_running || !((found & FOUND_DEVICE) || ((found & FOUND_BOOTREPO) && (found & FOUND_APKOVL)))) { size_t len; struct iovec iov; char cbuf[CMSG_SPACE(sizeof(struct ucred))]; @@ -702,10 +703,20 @@ int main(int argc, char *argv[]) struct msghdr hdr; struct sockaddr_nl cnls; + r = poll(fds, numfds, trigger_running ? -1 : conf.timeout); + if (r == -1) + err(1, "poll"); + + if (r == 0) { + dbg("exit due to timeout"); + break; + } + if (numfds > 1 && fds[1].revents & POLLIN) { close(fds[1].fd); fds[1].fd = -1; numfds--; + trigger_running = 0; pthread_join(tid, NULL); } @@ -744,20 +755,12 @@ int main(int argc, char *argv[]) event_count++; found |= process_uevent(buf, len, &conf); - if ((found & FOUND_DEVICE) - || ((found & FOUND_BOOTREPO) && (found & FOUND_APKOVL))) - break; - if (fds[0].revents & POLLHUP) { dbg("parent hung up\n"); break; } } - if (r == -1) - err(1, "poll"); - if (r == 0) - dbg("exit due to timeout"); dbg("modaliases: %i, forks: %i, events: %i, total bufsize: %zu", conf.modalias_count, conf.fork_count, -- cgit v1.2.3