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