2 #include "spawn-pipe.h"
5 * This is split up from the rest of git so that we might do
6 * something different on Windows, for example.
10 static void run_pager(const char *pager
)
13 * Work around bug in "less" by not starting it until we
20 select(1, &in
, NULL
, &in
, NULL
);
22 execlp(pager
, pager
, NULL
);
23 execl("/bin/sh", "sh", "-c", pager
, NULL
);
26 static pid_t pager_pid
;
27 static void collect_pager(void)
30 close(1); /* signals EOF to pager */
31 cwait(NULL
, pager_pid
, 0);
35 void setup_pager(void)
40 const char *pager_argv
[] = { "sh", "-c", NULL
, NULL
};
43 const char *pager
= getenv("GIT_PAGER");
48 pager
= pager_program
;
50 pager
= getenv("PAGER");
53 else if (!*pager
|| !strcmp(pager
, "cat"))
56 pager_in_use
= 1; /* means we are emitting to terminal */
68 /* return in the child */
76 /* The original process turns into the PAGER */
81 setenv("LESS", "FRSX", 0);
83 die("unable to execute pager '%s'", pager
);
87 pager_argv
[2] = pager
;
88 pager_pid
= spawnvpe_pipe(pager_argv
[0], pager_argv
, environ
, fd
, NULL
);
92 /* original process continues, but writes to the pipe */
96 /* this makes sure that the parent terminates after the pager */
97 atexit(collect_pager
);