From: Michael Tremer Date: Sat, 22 Mar 2025 16:11:44 +0000 (+0000) Subject: PTY: Remove the rest of the line buffering code X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3bcd1d3a951b7b50afdd5820698d6018e53787f1;p=pakfire.git PTY: Remove the rest of the line buffering code Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/pty.c b/src/pakfire/pty.c index 9f665b32..9f87efc4 100644 --- a/src/pakfire/pty.c +++ b/src/pakfire/pty.c @@ -400,25 +400,11 @@ static int pakfire_pty_fill_buffer(struct pakfire_pty* pty, int fd, struct pakfi return bytes_read; } -static ssize_t pakfire_pty_send_line(struct pakfire_pty* self, - struct pakfire_pty_stdio* stdio, const char* buffer, ssize_t length) { - int r; - - // Call the callback - r = stdio->callbacks.stdout_callback(self->ctx, stdio->callbacks.data, buffer, length); - if (r < 0) - return r; - - // We have consumed the entire line - return length; -} - /* Writes as much data as possible from the buffer */ static int pakfire_pty_drain_buffer(struct pakfire_pty* pty, int fd, struct pakfire_pty_stdio* stdio) { ssize_t bytes_written = 0; - char* eol = NULL; // Map any CRNL to just NL if (stdio->io & PAKFIRE_PTY_MAP_CRNL) @@ -426,20 +412,9 @@ static int pakfire_pty_drain_buffer(struct pakfire_pty* pty, int fd, struct pakf // Call the callback if possible if (stdio->callbacks.stdout_callback) { - // Try finding the end of a line - eol = memchr(stdio->buffer, '\n', stdio->buffered); - - // No newline found - if (!eol) { - if (!pakfire_pty_buffer_is_full(pty, stdio)) - return -ENOMSG; - - DEBUG(pty->ctx, "Buffer is full. Sending all content\n"); - eol = stdio->buffer + stdio->buffered - 1; - } - // Send the line - bytes_written = pakfire_pty_send_line(pty, stdio, stdio->buffer, eol - stdio->buffer + 1); + bytes_written = stdio->callbacks.stdout_callback(pty->ctx, + stdio->callbacks.data, stdio->buffer, stdio->buffered); // Abort on error if (bytes_written < 0) @@ -694,15 +669,6 @@ static int pakfire_pty_forward(struct pakfire_pty* pty) { } 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: - break; - // return 0; - default: ERROR(pty->ctx, "Failed writing to standard output: %s\n", strerror(-r)); goto ERROR;