Mercurial > hg
diff contrib/chg/procutil.c @ 30692:23ddd43ba866
chg: let procutil maintain its own pagerpid
Previously, chg.c maintains the pagerpid. Let's move it to procutil.c.
Note: chg.c still have a pagerpid to decide whether to call attachio or not.
In the future, attachio may be moved from hgc_open to hgc_runcommand, and
hgc_runcommand handles both pager and attachio so we don't need to run
attachio twice. And chg.c will be free of pagerpid.
author | Jun Wu <quark@fb.com> |
---|---|
date | Mon, 02 Jan 2017 14:43:37 +0000 |
parents | 7adb60660496 |
children | baee0f47b533 |
line wrap: on
line diff
--- a/contrib/chg/procutil.c Mon Jan 02 14:10:32 2017 +0000 +++ b/contrib/chg/procutil.c Mon Jan 02 14:43:37 2017 +0000 @@ -159,6 +159,7 @@ * Return 0 if pager is not started, or pid of the pager */ static pid_t setuppager(const char *pagercmd) { + assert(pagerpid == 0); if (!pagercmd) return 0; @@ -177,6 +178,7 @@ goto error; } close(pipefds[1]); + pagerpid = pid; return pid; } else { dup2(pipefds[0], fileno(stdin)); @@ -197,13 +199,16 @@ return 0; } -static void waitpager(pid_t pid) +static void waitpager(void) { + if (pagerpid == 0) + return; + /* close output streams to notify the pager its input ends */ fclose(stdout); fclose(stderr); while (1) { - pid_t ret = waitpid(pid, NULL, 0); + pid_t ret = waitpid(pagerpid, NULL, 0); if (ret == -1 && errno == EINTR) continue; break;