Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F160383346
D57563.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D57563.diff
View Options
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c
--- a/usr.bin/grep/util.c
+++ b/usr.bin/grep/util.c
@@ -45,6 +45,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include <wchar.h>
#include <wctype.h>
@@ -767,12 +768,33 @@
* Print an entire line as-is, there are no inline matches to consider. This is
* used for printing context.
*/
-void grep_printline(struct str *line, int sep) {
+static struct timespec printline_last_flush = { 0, 0 };
+
+static void
+flush_if_stalled(void)
+{
+ struct timespec now;
+
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if (now.tv_sec > printline_last_flush.tv_sec ||
+ (now.tv_sec == printline_last_flush.tv_sec &&
+ now.tv_nsec - printline_last_flush.tv_nsec > 100000000)) {
+ fflush(stdout);
+ printline_last_flush = now;
+ }
+}
+
+void
+grep_printline(struct str *line, int sep)
+{
printline_metadata(line, sep);
fwrite(line->dat, line->len, 1, stdout);
putchar(fileeol);
- fflush(stdout);
+ if (lbflag)
+ fflush(stdout);
+ else
+ flush_if_stalled();
}
static void
@@ -879,7 +901,7 @@
*last_out = pc->ln.len;
}
putchar('\n');
- fflush(stdout);
+ flush_if_stalled();
} else if (!oflag) {
/*
* -o is terminated on every match output, so this
@@ -890,7 +912,7 @@
*/
terminated = false;
} else {
- fflush(stdout);
+ flush_if_stalled();
}
} else
grep_printline(&pc->ln, sep);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jun 24, 11:15 PM (1 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33965290
Default Alt Text
D57563.diff (1 KB)
Attached To
Mode
D57563: grep: periodic timer-based fflush instead of unconditional per-line flush
Attached
Detach File
Event Timeline
Log In to Comment