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
24 FD_SET(0, &exception);
25 select(1, &in, NULL, &exception, NULL);
27 setenv("LESS", "FRSX", 0);
30 static const char *pager_argv[] = { "sh", "-c", NULL, NULL };
31 static struct child_process pager_process;
33 static void wait_for_pager(void)
37 /* signal EOF to pager */
40 finish_command(&pager_process);
43 static void wait_for_pager_signal(int signo)
50 void setup_pager(void)
52 const char *pager = getenv("PERF_PAGER");
57 pager = getenv("PAGER");
58 if (!(pager || access("/usr/bin/pager", X_OK)))
59 pager = "/usr/bin/pager";
60 if (!(pager || access("/usr/bin/less", X_OK)))
61 pager = "/usr/bin/less";
64 if (!*pager || !strcmp(pager, "cat"))
67 spawned_pager = 1; /* means we are emitting to terminal */
70 pager_argv[2] = pager;
71 pager_process.argv = pager_argv;
72 pager_process.in = -1;
73 pager_process.preexec_cb = pager_preexec;
75 if (start_command(&pager_process))
78 /* original process continues, but writes to the pipe */
79 dup2(pager_process.in, 1);
81 dup2(pager_process.in, 2);
82 close(pager_process.in);
84 /* this makes sure that the parent terminates after the pager */
85 sigchain_push_common(wait_for_pager_signal);
86 atexit(wait_for_pager);
89 int pager_in_use(void)
96 env = getenv("PERF_PAGER_IN_USE");
97 return env ? perf_config_bool("PERF_PAGER_IN_USE", env) : 0;