diff contrib/chg/chg.c @ 31890:ca7af5d15b21

chg: always wait for pager Previously, when runcommand raises, chg aborts with, and does not wait for pager. The call stack is like: hgc_runcommand -> handleresponse -> readchannel -> debugmsg("failed to read channel") -> exit(255) That means, chg returns to the shell, then both the pager and the shell will read from the terminal at the same time, causing problems. This patch fixes that by using "atexit" to register the pager cleanup function so chg will always wait for pager even if runcommand raises.
author Jun Wu <quark@fb.com>
date Tue, 11 Apr 2017 18:31:40 -0700
parents a68510b69f41
children 50788d1ae6cc
line wrap: on
line diff
--- a/contrib/chg/chg.c	Sun Apr 09 19:09:07 2017 +0200
+++ b/contrib/chg/chg.c	Tue Apr 11 18:31:40 2017 -0700
@@ -447,11 +447,11 @@
 	}
 
 	setupsignalhandler(hgc_peerpid(hgc), hgc_peerpgid(hgc));
+	atexit(waitpager);
 	int exitcode = hgc_runcommand(hgc, argv + 1, argc - 1);
 	restoresignalhandler();
 	hgc_close(hgc);
 	freecmdserveropts(&opts);
-	waitpager();
 
 	return exitcode;
 }