aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2015-10-19 08:31:50 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2015-10-19 08:47:03 +0000
commit384c6f27bb91b332c263de25a0a510507ed523a9 (patch)
treec0019a5102f11e7333c44017481171ad5646e730
parentcb3bc06f5ae4a9c3e706babd0a2c009058c0940f (diff)
downloadmkinitfs-384c6f27bb91b332c263de25a0a510507ed523a9.tar.bz2
mkinitfs-384c6f27bb91b332c263de25a0a510507ed523a9.tar.xz
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.
-rw-r--r--nlplug-findfs.c25
1 files changed, 14 insertions, 11 deletions
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,