home: hub: mkinitfs

Download patch

ref: 63d9cbed3d73f9a9d88927440c098d127ebe2c92
parent: da79c09e0d935615f06a79a519a6c5bb2117fef4
author: Natanael Copa <ncopa@alpinelinux.org>
date: Wed Nov 25 02:25:57 CST 2015

nlplug-findfs: use bit mask to indicate running thread

Use a bit mask to indicate trigger thread. This is so we can have more
threads in future.

--- a/nlplug-findfs.c
+++ b/nlplug-findfs.c
@@ -45,6 +45,8 @@
 #define FOUND_BOOTREPO	0x2
 #define FOUND_APKOVL	0x4
 
+#define TRIGGER_THREAD		0x1
+
 static int dodebug;
 static char *default_envp[2];
 char *argv0;
@@ -694,7 +696,7 @@
 static void *trigger_thread(void *data)
 {
 	int fd = *(int *)data;
-	uint64_t ok = 1;
+	uint64_t ok = TRIGGER_THREAD;
 	struct recurse_opts opts = {
 		.searchname = "uevent",
 		.callback = trigger_uevent_cb,
@@ -737,7 +739,8 @@
 	struct ueventconf conf;
 	int event_count = 0;
 	size_t total_bytes = 0;
-	int found = 0, trigger_running = 0;
+	int found = 0;
+	unsigned int running_threads = 0;
 	char *program_argv[2] = {0,0};
 	pthread_t tid;
 	sigset_t sigchldmask;
@@ -803,10 +806,10 @@
 	fds[2].fd = eventfd(0, EFD_CLOEXEC);
 	fds[2].events = POLLIN;
 	pthread_create(&tid, NULL, trigger_thread, &fds[2].fd);
-	trigger_running = 1;
+	running_threads |= TRIGGER_THREAD;
 
 	while (1) {
-		r = poll(fds, numfds, (spawn_active(&spawnmgr) || trigger_running) ? -1 : conf.timeout);
+		r = poll(fds, numfds, (spawn_active(&spawnmgr) || running_threads) ? -1 : conf.timeout);
 		if (r == -1) {
 			if (errno == EINTR || errno == ERESTART)
 				continue;
@@ -885,11 +888,15 @@
 		}
 
 		if (fds[2].revents & POLLIN) {
+			uint64_t tmask = 0;
+			if (read(fds[2].fd, &tmask, sizeof(tmask)) < 0)
+				warn("eventfd");
+			dbg("terminating thread %x", tmask);
 			close(fds[2].fd);
 			fds[2].fd = -1;
 			fds[2].revents = 0;
 			numfds--;
-			trigger_running = 0;
+			running_threads &= ~tmask;
 			pthread_join(tid, NULL);
 		}
 	}