From edb88949ed47a29bdc855fb6ad0bc04694ea998f Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 18 Mar 2025 17:08:04 +0000 Subject: [PATCH] pty: Add more logging when reading/writing Signed-off-by: Michael Tremer --- src/pakfire/pty.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pakfire/pty.c b/src/pakfire/pty.c index 88c00ca5..241071a3 100644 --- a/src/pakfire/pty.c +++ b/src/pakfire/pty.c @@ -415,6 +415,8 @@ static int pakfire_pty_fill_buffer(struct pakfire_pty* pty, int fd, struct pakfi if (bytes_read < 0) return bytes_read; + DEBUG(pty->ctx, "Read %zd byte(s) from input callback\n", bytes_read); + // Otherwise read from the file descriptor } else if (fd >= 0) { bytes_read = read(fd, stdio->buffer + stdio->buffered, sizeof(stdio->buffer) - stdio->buffered); @@ -422,6 +424,8 @@ static int pakfire_pty_fill_buffer(struct pakfire_pty* pty, int fd, struct pakfi // Abort on errors if (bytes_read < 0) return -errno; + + DEBUG(pty->ctx, "Read %zd byte(s) from fd=%d\n", bytes_read, fd); } // Successful read @@ -597,6 +601,8 @@ static int pakfire_pty_drain_buffer(struct pakfire_pty* pty, int fd, struct pakf if (bytes_written < 0) return bytes_written; + DEBUG(pty->ctx, "Sent %zd byte(s) to output callback\n", bytes_written); + // Otherwise we write to the file descriptor } else if (fd >= 0) { bytes_written = write(fd, stdio->buffer, stdio->buffered); @@ -604,6 +610,8 @@ static int pakfire_pty_drain_buffer(struct pakfire_pty* pty, int fd, struct pakf // Abort on error if (bytes_written < 0) return -errno; + + DEBUG(pty->ctx, "Wrote %zd byte(s) to fd=%d\n", bytes_written, fd); } // Successful write @@ -635,8 +643,9 @@ static int pakfire_pty_forward(struct pakfire_pty* pty) { ((pty->master.io & PAKFIRE_PTY_READY_TO_READ) && !pakfire_pty_buffer_is_full(pty, &pty->stdout)) || ((pty->stdout.io & PAKFIRE_PTY_READY_TO_WRITE) && pakfire_pty_buffer_has_data(pty, &pty->stdout)) ) { - // DEBUG(pty->ctx, "PTY forward stdin=%x %zu, stdout=%x %zu, %x\n", - // pty->stdin.io, pty->stdin.buffered, pty->stdout.io, pty->stdout.buffered, pty->master.io); + // DEBUG(pty->ctx, "PTY forward stdin=%x %zu, stdout=%x %zu, %x, draining=%d, drained=%d\n", + // pty->stdin.io, pty->stdin.buffered, pty->stdout.io, pty->stdout.buffered, pty->master.io, + // pty->state == PAKFIRE_PTY_STATE_DRAINING, pakfire_pty_drained(pty)); // Read from standard input if (pty->stdin.io & PAKFIRE_PTY_READY_TO_READ) { -- 2.39.5