1#include"cache.h" 2 3/* 4 * This is split up from the rest of git so that we might do 5 * something different on Windows, for example. 6 */ 7 8static voidrun_pager(void) 9{ 10const char*prog =getenv("PAGER"); 11if(!prog) 12 prog ="less"; 13setenv("LESS","-S",0); 14execlp(prog, prog, NULL); 15} 16 17voidsetup_pager(void) 18{ 19 pid_t pid; 20int fd[2]; 21 22if(!isatty(1)) 23return; 24if(pipe(fd) <0) 25return; 26 pid =fork(); 27if(pid <0) { 28close(fd[0]); 29close(fd[1]); 30return; 31} 32 33/* return in the child */ 34if(!pid) { 35dup2(fd[1],1); 36close(fd[0]); 37close(fd[1]); 38return; 39} 40 41/* The original process turns into the PAGER */ 42dup2(fd[0],0); 43close(fd[0]); 44close(fd[1]); 45 46run_pager(); 47exit(255); 48}