diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2017-04-06 23:01:29 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2017-04-06 23:02:45 +0100 |
commit | 93f29f37a0df5ffdc3933c97075c111be091aaad (patch) | |
tree | 5ab554c32d25e513ca67cba76c8a58f5a7ee0d5d /tools/intel_error_decode.c | |
parent | 5bd718c8d68a98a1d87ddc400bb1e39e43c8e842 (diff) |
tools/intel_error_decode: Automatically open a pager
A feature I've wanted for a long time, just to save typing | less every
time. Implementation nabbed from aubinator_error_decode.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'tools/intel_error_decode.c')
-rw-r--r-- | tools/intel_error_decode.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/intel_error_decode.c b/tools/intel_error_decode.c index 363cd902..d49f4799 100644 --- a/tools/intel_error_decode.c +++ b/tools/intel_error_decode.c @@ -772,6 +772,30 @@ read_data_file(FILE *file) free(ring_name); } +static void setup_pager(void) +{ + int fds[2]; + + if (pipe(fds) == -1) + return; + + switch (fork()) { + case -1: + break; + case 0: + close(fds[1]); + dup2(fds[0], 0); + execlp("less", "less", "-FRSi", NULL); + break; + + default: + close(fds[0]); + dup2(fds[1], 1); + close(fds[1]); + break; + } +} + int main(int argc, char *argv[]) { @@ -797,6 +821,9 @@ main(int argc, char *argv[]) return 1; } + if (isatty(1)) + setup_pager(); + if (argc == 1) { if (isatty(0)) { path = "/sys/class/drm/card0/error"; |