2 #include "spawn-pipe.h"
4 #include <sys/select.h>
7 * This is split up from the rest of git so that we might do
8 * something different on Windows, for example.
12 static void run_pager(const char *pager
)
15 * Work around bug in "less" by not starting it until we
22 select(1, &in
, NULL
, &in
, NULL
);
24 execlp(pager
, pager
, NULL
);
25 execl("/bin/sh", "sh", "-c", pager
, NULL
);
28 static pid_t pager_pid
;
29 static void collect_pager(void)
31 close(1); /* signals EOF to pager */
32 cwait(NULL
, pager_pid
, 0);
36 void setup_pager(void)
41 const char *pager_argv
[] = { "sh", "-c", NULL
, NULL
};
44 const char *pager
= getenv("GIT_PAGER");
49 pager
= getenv("PAGER");
52 else if (!*pager
|| !strcmp(pager
, "cat"))
55 pager_in_use
= 1; /* means we are emitting to terminal */
67 /* return in the child */
75 /* The original process turns into the PAGER */
80 setenv("LESS", "FRSX", 0);
82 die("unable to execute pager '%s'", pager
);
86 pager_argv
[2] = pager
;
87 pager_pid
= spawnvpe_pipe(pager_argv
[0], pager_argv
, environ
, fd
, NULL
);
91 /* original process continues, but writes to the pipe */
95 /* this makes sure that the parent terminates after the pager */
96 atexit(collect_pager
);