aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2026-02-27 11:29:24 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2026-02-27 11:57:50 +0100
commit1068aa8220bda260f7713f1455d38b86c4fce684 (patch)
tree087dcc962165f6802da9ba386a1fb7781373e503 /miscutils
parentca3f4c6639b0cd638f5f8d08a76a5c231f543800 (diff)
downloadbusybox-w32-1068aa8220bda260f7713f1455d38b86c4fce684.tar.gz
busybox-w32-1068aa8220bda260f7713f1455d38b86c4fce684.tar.bz2
busybox-w32-1068aa8220bda260f7713f1455d38b86c4fce684.zip
less: make read error reporting actually visible
function old new delta m_status_print 252 275 +23 status_print 111 122 +11 read_lines 783 775 -8 .rodata 107141 107131 -10 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/2 up/down: 34/-18) Total: 16 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/less.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/miscutils/less.c b/miscutils/less.c
index 12bb31537..d275fd3b3 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -529,7 +529,7 @@ static void read_lines(void)
529 readpos = 0; 529 readpos = 0;
530 read_size = G.eof_error_ok; 530 read_size = G.eof_error_ok;
531 if (G.eof_error_ok <= 0) { 531 if (G.eof_error_ok <= 0) {
532 read_size = 0; // -1 would be seen as UNIT_MAX, prevent 532 read_size = 0; // -1 would be seen as UINT_MAX, prevent
533 if (G.eof_error_ok < 0 && errno == EAGAIN) 533 if (G.eof_error_ok < 0 && errno == EAGAIN)
534 G.eof_error_ok = 1; // "neither EOF nor error" 534 G.eof_error_ok = 1; // "neither EOF nor error"
535 goto reached_eof; 535 goto reached_eof;
@@ -637,10 +637,13 @@ static void read_lines(void)
637 if (ndelay_set == 0) // stdin was not nonblocking, restore that 637 if (ndelay_set == 0) // stdin was not nonblocking, restore that
638 fcntl(STDIN_FILENO, F_SETFL, fdflags); 638 fcntl(STDIN_FILENO, F_SETFL, fdflags);
639 639
640 if (G.eof_error_ok < 0) // error? 640 // Will not be seen (overwritten immediately)
641 print_statusline(bb_msg_read_error); 641 //if (G.eof_error_ok < 0) { // error?
642 // print_statusline(bb_msg_read_error);
643 // bb_error_msg("G.eof_error_ok:%d", G.eof_error_ok); sleep(5);
644 //} else
642#if ENABLE_FEATURE_LESS_FLAGS 645#if ENABLE_FEATURE_LESS_FLAGS
643 else if (G.eof_error_ok == 0) // EOF? 646 if (G.eof_error_ok == 0) // EOF?
644 num_lines = max_lineno; 647 num_lines = max_lineno;
645#endif 648#endif
646 649
@@ -715,17 +718,17 @@ static void m_status_print(void)
715 clear_line(); 718 clear_line();
716 printf(HIGHLIGHT"%s", filename); 719 printf(HIGHLIGHT"%s", filename);
717 if (num_files > 1) 720 if (num_files > 1)
718 printf(" (file %i of %i)", current_file, num_files); 721 printf(" (file %d of %d)", current_file, num_files);
719 722
720 first = safe_lineno(cur_fline); 723 first = safe_lineno(cur_fline);
721 last = (option_mask32 & FLAG_S) 724 last = (option_mask32 & FLAG_S)
722 ? MIN(first + max_displayed_line, max_lineno) 725 ? MIN(first + max_displayed_line, max_lineno)
723 : safe_lineno(cur_fline + max_displayed_line); 726 : safe_lineno(cur_fline + max_displayed_line);
724 printf(" lines %i-%i", first, last); 727 printf(" lines %d-%d", first, last);
725 728
726 update_num_lines(); 729 update_num_lines();
727 if (num_lines >= 0) 730 if (num_lines >= 0)
728 printf("/%i", num_lines); 731 printf("/%d", num_lines);
729 732
730 if (at_end()) { 733 if (at_end()) {
731 printf(" (END)"); 734 printf(" (END)");
@@ -733,8 +736,11 @@ static void m_status_print(void)
733 printf(" - next: %s", files[current_file]); 736 printf(" - next: %s", files[current_file]);
734 } else if (num_lines > 0) { 737 } else if (num_lines > 0) {
735 percent = (100 * last + num_lines/2) / num_lines; 738 percent = (100 * last + num_lines/2) / num_lines;
736 printf(" %i%%", percent <= 100 ? percent : 100); 739 printf(" %d%%", percent <= 100 ? percent : 100);
737 } 740 }
741 if (G.eof_error_ok < 0)
742 // Reproducer: strace -oLOG -e fault=read:error=EIO:when=2 less FILE
743 printf(" %s", bb_msg_read_error);
738 printf(NORMAL); 744 printf(NORMAL);
739} 745}
740#endif 746#endif
@@ -764,6 +770,9 @@ static void status_print(void)
764 p = "(END)"; 770 p = "(END)";
765 if (!cur_fline) 771 if (!cur_fline)
766 p = filename; 772 p = filename;
773 if (G.eof_error_ok < 0)
774 // Reproducer: strace -oLOG -e fault=read:error=EIO:when=2 less FILE
775 p = bb_msg_read_error;
767 if (num_files > 1) { 776 if (num_files > 1) {
768 printf(HIGHLIGHT"%s (file %i of %i)"NORMAL, 777 printf(HIGHLIGHT"%s (file %i of %i)"NORMAL,
769 p, current_file, num_files); 778 p, current_file, num_files);
@@ -1137,7 +1146,7 @@ static int64_t getch_nowait(void)
1137 int r; 1146 int r;
1138 /* NB: SIGWINCH interrupts poll() */ 1147 /* NB: SIGWINCH interrupts poll() */
1139 r = poll(pfd + dont_poll_stdin, 2 - dont_poll_stdin, -1); 1148 r = poll(pfd + dont_poll_stdin, 2 - dont_poll_stdin, -1);
1140 if (/*r < 0 && errno == EINTR &&*/ winch_counter) 1149 if (/*r < 0 && errno == EINTR &&*/ winch_counter != 0)
1141 return '\\'; /* anything which has no defined function */ 1150 return '\\'; /* anything which has no defined function */
1142 if (r) break; 1151 if (r) break;
1143 } 1152 }
@@ -1927,7 +1936,7 @@ int less_main(int argc, char **argv)
1927 int64_t keypress; 1936 int64_t keypress;
1928 1937
1929#if ENABLE_FEATURE_LESS_WINCH 1938#if ENABLE_FEATURE_LESS_WINCH
1930 while (WINCH_COUNTER) { 1939 while (WINCH_COUNTER != 0) {
1931 again: 1940 again:
1932 winch_counter--; 1941 winch_counter--;
1933 IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(kbd_fd, &width, &max_displayed_line); 1942 IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(kbd_fd, &width, &max_displayed_line);