chg: respect environment variables for pager
authorJun Wu <quark@fb.com>
Wed, 12 Apr 2017 16:50:23 -0700
changeset 31941 ac5527021097
parent 31940 6ce09d2cc2db
child 31942 bc0579a25f82
chg: respect environment variables for pager Previously chg runs the pager command without respecting its environment variables being told to use. This patch makes it so.
contrib/chg/hgclient.c
contrib/chg/procutil.c
contrib/chg/procutil.h
--- a/contrib/chg/hgclient.c	Mon Apr 10 17:36:40 2017 +0200
+++ b/contrib/chg/hgclient.c	Wed Apr 12 16:50:23 2017 -0700
@@ -252,7 +252,7 @@
 		ctx->datasize = sizeof(r_n);
 		writeblock(hgc);
 	} else if (strcmp(args[0], "pager") == 0) {
-		setuppager(args[1]);
+		setuppager(args[1], args + 3);
 		if (hgc->capflags & CAP_ATTACHIO)
 			attachio(hgc);
 		/* unblock the server */
--- a/contrib/chg/procutil.c	Mon Apr 10 17:36:40 2017 +0200
+++ b/contrib/chg/procutil.c	Wed Apr 12 16:50:23 2017 -0700
@@ -177,7 +177,7 @@
 
 /* This implementation is based on hgext/pager.py (post 369741ef7253)
  * Return 0 if pager is not started, or pid of the pager */
-pid_t setuppager(const char *pagercmd)
+pid_t setuppager(const char *pagercmd, const char *envp[])
 {
 	assert(pagerpid == 0);
 	if (!pagercmd)
@@ -205,7 +205,8 @@
 		close(pipefds[0]);
 		close(pipefds[1]);
 
-		int r = execlp("/bin/sh", "/bin/sh", "-c", pagercmd, NULL);
+		int r = execle("/bin/sh", "/bin/sh", "-c", pagercmd, NULL,
+				envp);
 		if (r < 0) {
 			abortmsgerrno("cannot start pager '%s'", pagercmd);
 		}
--- a/contrib/chg/procutil.h	Mon Apr 10 17:36:40 2017 +0200
+++ b/contrib/chg/procutil.h	Wed Apr 12 16:50:23 2017 -0700
@@ -15,7 +15,7 @@
 void restoresignalhandler(void);
 void setupsignalhandler(pid_t pid, pid_t pgid);
 
-pid_t setuppager(const char *pagercmd);
+pid_t setuppager(const char *pagercmd, const char *envp[]);
 void waitpager(void);
 
 #endif /* PROCUTIL_H_ */