diff options
author | Ingo Molnar <mingo@elte.hu> | 2009-05-27 03:50:13 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-05-27 03:59:00 -0400 |
commit | a930d2c0d0a685ab955472b08baad041cc5edb4a (patch) | |
tree | 988e0da70e64ef72437058828974d946328280af /Documentation/perf_counter/util/sigchain.c | |
parent | 23ac9cbed82b00ca3520bb81dbe9ea3b7a936a1b (diff) |
perf_counter tools: Add built-in pager support
Add Git's pager.c (and sigchain) code. A command only
has to call setup_pager() to get paged interactive
output.
Non-interactive (redirected, command-piped, etc.) uses
are not affected.
Update perf-report to make use of this.
[ Impact: new feature ]
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: John Kacur <jkacur@redhat.com>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'Documentation/perf_counter/util/sigchain.c')
-rw-r--r-- | Documentation/perf_counter/util/sigchain.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Documentation/perf_counter/util/sigchain.c b/Documentation/perf_counter/util/sigchain.c new file mode 100644 index 000000000000..1118b99e57d3 --- /dev/null +++ b/Documentation/perf_counter/util/sigchain.c | |||
@@ -0,0 +1,52 @@ | |||
1 | #include "sigchain.h" | ||
2 | #include "cache.h" | ||
3 | |||
4 | #define SIGCHAIN_MAX_SIGNALS 32 | ||
5 | |||
6 | struct sigchain_signal { | ||
7 | sigchain_fun *old; | ||
8 | int n; | ||
9 | int alloc; | ||
10 | }; | ||
11 | static struct sigchain_signal signals[SIGCHAIN_MAX_SIGNALS]; | ||
12 | |||
13 | static void check_signum(int sig) | ||
14 | { | ||
15 | if (sig < 1 || sig >= SIGCHAIN_MAX_SIGNALS) | ||
16 | die("BUG: signal out of range: %d", sig); | ||
17 | } | ||
18 | |||
19 | int sigchain_push(int sig, sigchain_fun f) | ||
20 | { | ||
21 | struct sigchain_signal *s = signals + sig; | ||
22 | check_signum(sig); | ||
23 | |||
24 | ALLOC_GROW(s->old, s->n + 1, s->alloc); | ||
25 | s->old[s->n] = signal(sig, f); | ||
26 | if (s->old[s->n] == SIG_ERR) | ||
27 | return -1; | ||
28 | s->n++; | ||
29 | return 0; | ||
30 | } | ||
31 | |||
32 | int sigchain_pop(int sig) | ||
33 | { | ||
34 | struct sigchain_signal *s = signals + sig; | ||
35 | check_signum(sig); | ||
36 | if (s->n < 1) | ||
37 | return 0; | ||
38 | |||
39 | if (signal(sig, s->old[s->n - 1]) == SIG_ERR) | ||
40 | return -1; | ||
41 | s->n--; | ||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | void sigchain_push_common(sigchain_fun f) | ||
46 | { | ||
47 | sigchain_push(SIGINT, f); | ||
48 | sigchain_push(SIGHUP, f); | ||
49 | sigchain_push(SIGTERM, f); | ||
50 | sigchain_push(SIGQUIT, f); | ||
51 | sigchain_push(SIGPIPE, f); | ||
52 | } | ||