Patchwork [2,of,3,V2] chg: detect chg started by chg

login
register
mail settings
Submitter Jun Wu
Date Feb. 26, 2016, 2:20 p.m.
Message ID <39999aaee9397d8f2182.1456496426@x1c>
Download mbox | patch
Permalink /patch/13412/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - Feb. 26, 2016, 2:20 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1456495992 0
#      Fri Feb 26 14:13:12 2016 +0000
# Node ID 39999aaee9397d8f21823dae5f5551fc5251feea
# Parent  ecefdf920cc8b8b983e06da8e82b8db0f67b85de
chg: detect chg started by chg

Sometimes people may create a symbol link from hg to chg, or write a wrapper
script named hg calling chg. Without $HG and $CHGHG set, this will lead to
chg executes itself causing deadlock. The user will notice chg hangs for some
time and aborts with a timed out message, without knowing the root cause and
how to solve it.

This patch sets a dummy environment variable before executing hg to detect
this situation, and print a fatal message with some possible solutions.
Yuya Nishihara - Feb. 27, 2016, 6:43 a.m.
On Fri, 26 Feb 2016 14:20:26 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1456495992 0
> #      Fri Feb 26 14:13:12 2016 +0000
> # Node ID 39999aaee9397d8f21823dae5f5551fc5251feea
> # Parent  ecefdf920cc8b8b983e06da8e82b8db0f67b85de
> chg: detect chg started by chg

I'm not excited about this change in that it uses environment variables, but
this should be an improvement for users.

Folded the next patch and pushed to the clowncopter, thanks.

Patch

diff --git a/contrib/chg/chg.c b/contrib/chg/chg.c
--- a/contrib/chg/chg.c
+++ b/contrib/chg/chg.c
@@ -227,6 +227,8 @@ 
 	memcpy(argv + baseargvsize, opts->args, sizeof(char *) * opts->argsize);
 	argv[argsize - 1] = NULL;
 
+	if (putenv("CHGINTERNALMARK=") != 0)
+		abortmsg("failed to putenv (errno = %d)", errno);
 	if (execvp(hgcmd, (char **)argv) < 0)
 		abortmsg("failed to exec cmdserver (errno = %d)", errno);
 	free(argv);
@@ -490,6 +492,12 @@ 
 	if (getenv("CHGDEBUG"))
 		enabledebugmsg();
 
+	if (getenv("CHGINTERNALMARK"))
+		abortmsg("chg started by chg detected.\n"
+			 "Please make sure ${HG:-hg} is not a symlink or "
+			 "wrapper to chg. Alternatively, set $CHGHG to the "
+			 "path of real hg.");
+
 	if (isunsupported(argc, argv))
 		execoriginalhg(argv);