##// END OF EJS Templates
chg: populate CHGHG if not set...
Arun Kulshreshtha -
r51279:cf4d2f31 stable
parent child Browse files
Show More
@@ -232,12 +232,17 b' static const char *gethgcmd(void)'
232 232 hgcmd = "hg";
233 233 #endif
234 234 }
235 /* Set $CHGHG to the path to the seleted hg executable if it wasn't
236 * already set. This has the effect of ensuring that a new command
237 * server will be spawned if the existing command server is running from
238 * an executable at a different path. */
239 if (setenv("CHGHG", hgcmd, 1) != 0)
240 abortmsgerrno("failed to setenv");
235 241 return hgcmd;
236 242 }
237 243
238 static void execcmdserver(const struct cmdserveropts *opts)
244 static void execcmdserver(const char *hgcmd, const struct cmdserveropts *opts)
239 245 {
240 const char *hgcmd = gethgcmd();
241 246
242 247 const char *baseargv[] = {
243 248 hgcmd, "serve", "--no-profile", "--cmdserver",
@@ -375,11 +380,16 b' static hgclient_t *connectcmdserver(stru'
375 380
376 381 debugmsg("start cmdserver at %s", opts->initsockname);
377 382
383 /* Get the path to the hg executable before we fork because this
384 * function might update the environment, and we want this to be
385 * reflected in both the parent and child processes. */
386 const char *hgcmd = gethgcmd();
387
378 388 pid_t pid = fork();
379 389 if (pid < 0)
380 390 abortmsg("failed to fork cmdserver process");
381 391 if (pid == 0) {
382 execcmdserver(opts);
392 execcmdserver(hgcmd, opts);
383 393 } else {
384 394 hgc = retryconnectcmdserver(opts, pid);
385 395 }
@@ -484,7 +494,7 b' static void execoriginalhg(const char *a'
484 494 abortmsgerrno("failed to exec original hg");
485 495 }
486 496
487 int main(int argc, const char *argv[], const char *envp[])
497 int main(int argc, const char *argv[])
488 498 {
489 499 if (getenv("CHGDEBUG"))
490 500 enabledebugmsg();
@@ -519,7 +529,10 b' int main(int argc, const char *argv[], c'
519 529 hgc = connectcmdserver(&opts);
520 530 if (!hgc)
521 531 abortmsg("cannot open hg client");
522 hgc_setenv(hgc, envp);
532 /* Use `environ(7)` instead of the optional `envp` argument to
533 * `main` because `envp` does not update when the environment
534 * changes, but `environ` does. */
535 hgc_setenv(hgc, (const char *const *)environ);
523 536 const char **insts = hgc_validate(hgc, argv + 1, argc - 1);
524 537 int needreconnect = runinstructions(&opts, insts);
525 538 free(insts);
General Comments 0
You need to be logged in to leave comments. Login now