From: Michael Tremer Date: Sat, 19 Oct 2024 13:32:29 +0000 (+0000) Subject: pty: Hack to avoid lock-up when we don't have a newline X-Git-Tag: 0.9.30~988 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=380aca559db63a3077b90dad0738a9c658cfc432;p=pakfire.git pty: Hack to avoid lock-up when we don't have a newline Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pty.c b/src/libpakfire/pty.c index 3307b6d40..7256d8961 100644 --- a/src/libpakfire/pty.c +++ b/src/libpakfire/pty.c @@ -436,7 +436,7 @@ static int pakfire_pty_drain_buffer(struct pakfire_pty* pty, int fd, struct pakf // No newline found if (!eol) { if (!pakfire_pty_buffer_is_full(pty, stdio)) - return 0; + return -ENOMSG; CTX_DEBUG(pty->ctx, "Buffer is full. Sending all content\n"); eol = stdio->buffer + stdio->buffered - 1; @@ -482,14 +482,14 @@ static int pakfire_pty_forward(struct pakfire_pty* pty) { return -EINVAL; } - //printf("GOT HERE %x, %x, %x\n", pty->stdin.io, pty->stdout.io, pty->master.io); - while ( ((pty->stdin.io & PAKFIRE_PTY_READY_TO_READ) && !pakfire_pty_buffer_is_full(pty, &pty->stdin)) || ((pty->master.io & PAKFIRE_PTY_READY_TO_WRITE) && pakfire_pty_buffer_has_data(pty, &pty->stdin)) || ((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)) ) { + // CTX_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); // Read from standard input if (pty->stdin.io & PAKFIRE_PTY_READY_TO_READ) { @@ -598,6 +598,14 @@ static int pakfire_pty_forward(struct pakfire_pty* pty) { pty->stdout.io |= PAKFIRE_PTY_HANGUP; break; + // This is a special hack for when we have data in the buffer + // but cannot send it to the callback, yet, because we have not + // read to the end of the line. + // To avoid getting stuck in this loop for forever, we simply + // exit and let the loop call us again. + case ENOMSG: + return 0; + default: CTX_ERROR(pty->ctx, "Failed writing to standard output: %s\n", strerror(-r)); goto ERROR;