From 16ea9c7aa337b1acb7c1041b4730a4b168096706 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Thu, 18 Jan 2007 14:18:11 +0100 Subject: [PATCH] Make sure that the pager terminates before the process that feeds it. Since the pager was spawned as child process, it does not notice when the parent (which feeds its stdin) terminates. If the pager is 'less' it so looses control over the terminal and cannot be controled by the user anymore. For this reason, we register a function atexit() that explicitly waits for the pager to terminate. --- pager.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pager.c b/pager.c index b2a37e2658..d72c5e8d94 100644 --- a/pager.c +++ b/pager.c @@ -12,6 +12,13 @@ static void run_pager(const char *pager) execlp(pager, pager, NULL); execl("/bin/sh", "sh", "-c", pager, NULL); } +#else +static pid_t pager_pid; +static void collect_pager(void) +{ + close(1); /* signals EOF to pager */ + cwait(NULL, pager_pid, 0); +} #endif void setup_pager(void) @@ -65,11 +72,15 @@ void setup_pager(void) #else /* spawn the pager */ pager_argv[2] = pager; - if (spawnvpe_pipe(pager_argv[0], pager_argv, environ, fd, NULL) < 0) + pager_pid = spawnvpe_pipe(pager_argv[0], pager_argv, environ, fd, NULL); + if (pager_pid < 0) return; /* original process continues, but writes to the pipe */ dup2(fd[1], 1); close(fd[1]); + + /* this makes sure that the parent terminates after the pager */ + atexit(collect_pager); #endif }