[make-initrd] [PATCH 1/3] ueventd: Simplify call of the queue handler

Alexey Gladkov gladkov.alexey at gmail.com
Sat May 20 19:37:46 MSK 2023


There is no need to iterate over fd_list[] on every event. Instead of a
descriptor, we can use a pointer to the structure itself.

Signed-off-by: Alexey Gladkov <gladkov.alexey at gmail.com>
---
 datasrc/ueventd/ueventd.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/datasrc/ueventd/ueventd.c b/datasrc/ueventd/ueventd.c
index 67bc3dda..9c20594f 100644
--- a/datasrc/ueventd/ueventd.c
+++ b/datasrc/ueventd/ueventd.c
@@ -401,7 +401,7 @@ int setup_epoll_fd(struct fd_handler list[FD_MAX])
 		rd_fatal("epoll_create1: %m");
 
 	for (int i = 0; i < FD_MAX; i++) {
-		ev.data.fd = list[i].fd;
+		ev.data.ptr = &list[i];
 
 		if (epoll_ctl(epollfd, EPOLL_CTL_ADD, list[i].fd, &ev) < 0)
 			rd_fatal("epoll_ctl: %m");
@@ -531,12 +531,11 @@ int main(int argc, char **argv)
 		for (i = 0; i < fdcount; i++) {
 			if (!(ev[i].events & EPOLLIN))
 				continue;
-			for (int k = 0; k < FD_MAX; k++) {
-				if (ev[i].data.fd != fd_list[k].fd)
-					continue;
-				if (fd_list[k].fd_handler(fd_list[k].fd) != 0)
-					goto done;
-			}
+
+			struct fd_handler *fde = ev[i].data.ptr;
+
+			if (fde->fd_handler(fde->fd) != 0)
+				goto done;
 		}
 
 		for (e = watch_list; e; e = e->next) {
-- 
2.33.8



More information about the Make-initrd mailing list