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))
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) {
// 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
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)
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