2 #include "run-command.h"
6 * This is split up from the rest of git so that we can do
7 * something different on Windows.
10 static int spawned_pager;
12 static void pager_preexec(void)
15 * Work around bug in "less" by not starting it until we
22 select(1, &in, NULL, &in, NULL);
24 setenv("LESS", "FRSX", 0);
27 static const char *pager_argv[] = { "sh", "-c", NULL, NULL };
28 static struct child_process pager_process;
30 static void wait_for_pager(void)
34 /* signal EOF to pager */
37 finish_command(&pager_process);
40 static void wait_for_pager_signal(int signo)
47 void setup_pager(void)
49 const char *pager = getenv("PERF_PAGER");
55 perf_config(perf_default_config, NULL);
56 pager = pager_program;
59 pager = getenv("PAGER");
62 else if (!*pager || !strcmp(pager, "cat"))
65 spawned_pager = 1; /* means we are emitting to terminal */
68 pager_argv[2] = pager;
69 pager_process.argv = pager_argv;
70 pager_process.in = -1;
71 pager_process.preexec_cb = pager_preexec;
73 if (start_command(&pager_process))
76 /* original process continues, but writes to the pipe */
77 dup2(pager_process.in, 1);
79 dup2(pager_process.in, 2);
80 close(pager_process.in);
82 /* this makes sure that the parent terminates after the pager */
83 sigchain_push_common(wait_for_pager_signal);
84 atexit(wait_for_pager);
87 int pager_in_use(void)
94 env = getenv("PERF_PAGER_IN_USE");
95 return env ? perf_config_bool("PERF_PAGER_IN_USE", env) : 0;