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
)
12 execlp(pager
, pager
, NULL
);
13 execl("/bin/sh", "sh", "-c", pager
, NULL
);
16 static pid_t pager_pid
;
17 static void collect_pager(void)
19 close(1); /* signals EOF to pager */
20 cwait(NULL
, pager_pid
, 0);
24 void setup_pager(void)
29 const char *pager_argv
[] = { "sh", "-c", NULL
, NULL
};
32 const char *pager
= getenv("GIT_PAGER");
37 pager
= getenv("PAGER");
40 else if (!*pager
|| !strcmp(pager
, "cat"))
43 pager_in_use
= 1; /* means we are emitting to terminal */
55 /* return in the child */
63 /* The original process turns into the PAGER */
68 setenv("LESS", "FRSX", 0);
70 die("unable to execute pager '%s'", pager
);
74 pager_argv
[2] = pager
;
75 pager_pid
= spawnvpe_pipe(pager_argv
[0], pager_argv
, environ
, fd
, NULL
);
79 /* original process continues, but writes to the pipe */
83 /* this makes sure that the parent terminates after the pager */
84 atexit(collect_pager
);