From: Michael Tremer Date: Sat, 16 Dec 2023 13:19:54 +0000 (+0000) Subject: jail: Align processing of file descriptors in the event loop X-Git-Tag: 0.9.30~1279 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a2d03d52983aa9ff6e70a28de7d6a0f178e168a6;p=pakfire.git jail: Align processing of file descriptors in the event loop This is slightly easier to read than checking the event type first and then handle the rest. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index 5f3884445..45be6755e 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -1204,11 +1204,6 @@ static int pakfire_jail_wait(struct pakfire_jail* jail, struct pakfire_jail_exec int e = events[i].events; int fd = events[i].data.fd; - struct pakfire_log_buffer* buffer = NULL; - pakfire_jail_communicate_out callback = NULL; - void* data = NULL; - int priority; - // Handle PTY forwarding events if (ctx->pty.master.fd == fd) { if (e & (EPOLLIN|EPOLLHUP)) @@ -1247,12 +1242,10 @@ static int pakfire_jail_wait(struct pakfire_jail* jail, struct pakfire_jail_exec CTX_ERROR(jail->ctx, "Failed forwarding the PTY: %s\n", strerror(-r)); goto ERROR; } - } - // Check if there is any data to be read - if (e & EPOLLIN) { - // Handle any changes to the PIDFD - if (fd == pidfd) { + // Handle any changes to the PIDFD + } else if (pidfd == fd) { + if (e & EPOLLIN) { // Call waidid() and store the result r = waitid(P_PIDFD, ctx->pidfd, &ctx->status, WEXITED); if (r) { @@ -1263,10 +1256,11 @@ static int pakfire_jail_wait(struct pakfire_jail* jail, struct pakfire_jail_exec // Mark that we have ended so that we will process the remaining // events from epoll() now, but won't restart the outer loop. ended = 1; - continue; + } - // Handle timer events - } else if (fd == timerfd) { + // Handle timer events + } else if (timerfd == fd) { + if (e & EPOLLIN) { DEBUG(jail->pakfire, "Timer event received\n"); // Disarm the timer @@ -1288,33 +1282,11 @@ static int pakfire_jail_wait(struct pakfire_jail* jail, struct pakfire_jail_exec goto ERROR; } } + } - // Don't fall through to log processing - continue; - - // Handle logging messages - } else if (fd == log_INFO) { - buffer = &ctx->buffers.log_INFO; - priority = LOG_INFO; - - callback = pakfire_jail_log; - - } else if (fd == log_ERROR) { - buffer = &ctx->buffers.log_ERROR; - priority = LOG_ERR; - - callback = pakfire_jail_log; - -#ifdef ENABLE_DEBUG - } else if (fd == log_DEBUG) { - buffer = &ctx->buffers.log_DEBUG; - priority = LOG_DEBUG; - - callback = pakfire_jail_log; -#endif /* ENABLE_DEBUG */ - - // Handle socket messages - } else if (fd == socket_recv) { + // Handle socket messages + } else if (socket_recv == fd) { + if (e & EPOLLIN) { // Receive the passed FD r = pakfire_jail_recv_fd(jail, socket_recv, &fd); if (r) @@ -1328,19 +1300,41 @@ static int pakfire_jail_wait(struct pakfire_jail* jail, struct pakfire_jail_exec goto ERROR; } } + } - // Don't fall through to log processing - continue; + // Handle log INFO messages + } else if (log_INFO == fd) { + if (e & EPOLLIN) { + r = pakfire_jail_handle_log(jail, ctx, LOG_INFO, fd, + &ctx->buffers.log_INFO, pakfire_jail_log, NULL); + if (r) + goto ERROR; + } - } else { - DEBUG(jail->pakfire, "Received invalid file descriptor %d\n", fd); - continue; + // Handle log ERROR messages + } else if (log_ERROR == fd) { + if (e & EPOLLIN) { + r = pakfire_jail_handle_log(jail, ctx, LOG_ERR, fd, + &ctx->buffers.log_ERROR, pakfire_jail_log, NULL); + if (r) + goto ERROR; } - // Handle log event - r = pakfire_jail_handle_log(jail, ctx, priority, fd, buffer, callback, data); - if (r) - goto ERROR; +#ifdef ENABLE_DEBUG + // Handle log DEBUG messages + } else if (log_DEBUG == fd) { + if (e & EPOLLIN) { + r = pakfire_jail_handle_log(jail, ctx, LOG_DEBUG, fd, + &ctx->buffers.log_DEBUG, pakfire_jail_log, NULL); + if (r) + goto ERROR; + } +#endif /* ENABLE_DEBUG */ + + // Log a message for anything else + } else { + DEBUG(jail->pakfire, "Received invalid file descriptor %d\n", fd); + continue; } // Check if any file descriptors have been closed diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 8ad78a580..072ba8f93 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -292,7 +292,7 @@ static int pakfire_populate_pool(struct pakfire* pakfire) { #ifdef ENABLE_DEBUG // Enable debug output - pool_setdebuglevel(pool, 3); + //pool_setdebuglevel(pool, 3); #endif // Set architecture of the pool