Browse Source

Use faux_write_block() for blocking output to possible non-blocking terminal fd

Serj Kalichev 1 year ago
parent
commit
bee389c852
1 changed files with 3 additions and 4 deletions
  1. 3 4
      bin/klish/interactive.c

+ 3 - 4
bin/klish/interactive.c

@@ -729,15 +729,14 @@ static bool_t interactive_stdout_cb(ktp_session_t *ktp, const char *line, size_t
 
 	// Write to pager's pipe if pager is really working
 	if (ctx->pager_working == TRI_TRUE) {
-		if (fwrite(line, 1, len, ctx->pager_pipe) == 0) {
+		if (faux_write_block(fileno(ctx->pager_pipe), line, len) <= 0) {
 			// If we can't write to pager pipe then try stdout.
-			if (write(STDOUT_FILENO, line, len) < 0)
+			if (faux_write_block(STDOUT_FILENO, line, len) < 0)
 				return BOOL_FALSE;
 			return BOOL_TRUE; // Don't break the loop
 		}
-		fflush(ctx->pager_pipe);
 	} else {
-		if (write(STDOUT_FILENO, line, len) < 0)
+		if (faux_write_block(STDOUT_FILENO, line, len) < 0)
 			return BOOL_FALSE;
 	}