Patchwork [4,of,4,V3] chg: limit reconnect attempts

login
register
mail settings
Submitter Jun Wu
Date March 5, 2016, 2 p.m.
Message ID <df797ea9e98c01df79b4.1457186413@x1c>
Download mbox | patch
Permalink /patch/13616/
State Superseded
Commit ffd3ac07b1d79dda7f57bd826208fdaf92a76717
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - March 5, 2016, 2 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1456915378 0
#      Wed Mar 02 10:42:58 2016 +0000
# Node ID df797ea9e98c01df79b4ee1211195c4ac78ccbc6
# Parent  3e0cbe287f05a9dc3601f5104f0b051b9dcf5d2a
chg: limit reconnect attempts

Some users may have hg as a wrapper script which sets sensitive environment
variables (like setting up virtualenv). This will make chg redirect forever
because the environment variables are never considered up to date.
This patch adds a limit (10) for reconnect attempts and warn the user with
a possible solution if the limit is exceeded.

Patch

diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -549,6 +549,7 @@ 
 	}
 
 	hgclient_t *hgc;
+	size_t retry = 0;
 	while (1) {
 		hgc = connectcmdserver(&opts);
 		if (!hgc)
@@ -559,6 +560,13 @@ 
 			break;
 		runinstructions(&opts, insts);
 		hgc_close(hgc);
+		if (++retry > 10)
+			abortmsg("too many redirections.\n"
+				 "Please make sure %s is not a wrapper which "
+				 "changes sensitive environment variables "
+				 "before executing hg. If you have to use a "
+				 "wrapper, wrap chg instead of hg.",
+				 gethgcmd());
 	}
 
 	setupsignalhandler(hgc_peerpid(hgc));