home: hub: mkinitfs

Download patch

ref: c6b7670ec3aab4f65d480230014bad51d7f4bdd9
parent: edb3c808c174c8a386d2c976457c2803fa1a90f1
author: Natanael Copa <ncopa@alpinelinux.org>
date: Thu Sep 24 04:13:11 CDT 2015

nlplug-findfs: refactor recursing dir tree

we need a more general recurse function so we can search for boot repos
and similar.

--- a/nlplug-findfs.c
+++ b/nlplug-findfs.c
@@ -379,7 +379,12 @@
 	return dispatch_uevent(&ev, conf);
 }
 
-void trigger_events(const char *dir)
+struct recurse_opts {
+	const char *searchname;
+	void (*callback)(const char *);
+};
+
+void recurse_dir(const char *dir, struct recurse_opts *opts)
 {
 	DIR *d = opendir(dir);
 	struct dirent *entry;
@@ -389,32 +394,40 @@
 
 	while ((entry = readdir(d)) != NULL) {
 		char path[PATH_MAX];
-		if (!(entry->d_type & DT_DIR) \
-		    && strcmp(entry->d_name, "uevent") != 0)
+		if (entry->d_type & DT_DIR) {
+			if (entry->d_name[0] == '.')
+				continue;
+		} else if (opts->searchname
+			   && strcmp(entry->d_name, opts->searchname) != 0) {
 			continue;
+		}
 
-		if (entry->d_name[0] == '.')
-			continue;
-
 		snprintf(path, sizeof(path), "%s/%s", dir, entry->d_name);
-
 		if (entry->d_type & DT_DIR)
-			trigger_events(path);
-		else {
-			int fd = open(path, O_WRONLY);
-			write(fd, "add", 3);
-			close(fd);
-		}
+			recurse_dir(path, opts);
+		else
+			opts->callback(path);
 	}
 	closedir(d);
 }
 
+void trigger_uevent_cb(const char *path)
+{
+	int fd = open(path, O_WRONLY);
+	write(fd, "add", 3);
+	close(fd);
+}
+
 void *trigger_thread(void *data)
 {
 	int fd = *(int *)data;
 	uint64_t ok = 1;
-	trigger_events("/sys/bus");
-	trigger_events("/sys/devices");
+	struct recurse_opts opts = {
+		.searchname = "uevent",
+		.callback = trigger_uevent_cb,
+	};
+	recurse_dir("/sys/bus", &opts);
+	recurse_dir("/sys/devices", &opts);
 	write(fd, &ok, sizeof(ok));
 	return NULL;
 }