##// END OF EJS Templates
chg: remove sockdirfd...
Jun Wu -
r30676:b83bddfc default
parent child Browse files
Show More
@@ -1,644 +1,638
1 1 /*
2 2 * A fast client for Mercurial command server
3 3 *
4 4 * Copyright (c) 2011 Yuya Nishihara <yuya@tcha.org>
5 5 *
6 6 * This software may be used and distributed according to the terms of the
7 7 * GNU General Public License version 2 or any later version.
8 8 */
9 9
10 10 #include <assert.h>
11 11 #include <errno.h>
12 12 #include <fcntl.h>
13 13 #include <signal.h>
14 14 #include <stdio.h>
15 15 #include <stdlib.h>
16 16 #include <string.h>
17 17 #include <sys/file.h>
18 18 #include <sys/stat.h>
19 19 #include <sys/types.h>
20 20 #include <sys/un.h>
21 21 #include <sys/wait.h>
22 22 #include <time.h>
23 23 #include <unistd.h>
24 24
25 25 #include "hgclient.h"
26 26 #include "util.h"
27 27
28 28 #ifndef UNIX_PATH_MAX
29 29 #define UNIX_PATH_MAX (sizeof(((struct sockaddr_un *)NULL)->sun_path))
30 30 #endif
31 31
32 32 struct cmdserveropts {
33 33 char sockname[UNIX_PATH_MAX];
34 34 char initsockname[UNIX_PATH_MAX];
35 35 char redirectsockname[UNIX_PATH_MAX];
36 36 size_t argsize;
37 37 const char **args;
38 int sockdirfd;
39 38 };
40 39
41 40 static void initcmdserveropts(struct cmdserveropts *opts) {
42 41 memset(opts, 0, sizeof(struct cmdserveropts));
43 opts->sockdirfd = -1;
44 42 }
45 43
46 44 static void freecmdserveropts(struct cmdserveropts *opts) {
47 45 free(opts->args);
48 46 opts->args = NULL;
49 47 opts->argsize = 0;
50 if (opts->sockdirfd >= 0) {
51 close(opts->sockdirfd);
52 opts->sockdirfd = -1;
53 }
54 48 }
55 49
56 50 /*
57 51 * Test if an argument is a sensitive flag that should be passed to the server.
58 52 * Return 0 if not, otherwise the number of arguments starting from the current
59 53 * one that should be passed to the server.
60 54 */
61 55 static size_t testsensitiveflag(const char *arg)
62 56 {
63 57 static const struct {
64 58 const char *name;
65 59 size_t narg;
66 60 } flags[] = {
67 61 {"--config", 1},
68 62 {"--cwd", 1},
69 63 {"--repo", 1},
70 64 {"--repository", 1},
71 65 {"--traceback", 0},
72 66 {"-R", 1},
73 67 };
74 68 size_t i;
75 69 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); ++i) {
76 70 size_t len = strlen(flags[i].name);
77 71 size_t narg = flags[i].narg;
78 72 if (memcmp(arg, flags[i].name, len) == 0) {
79 73 if (arg[len] == '\0') {
80 74 /* --flag (value) */
81 75 return narg + 1;
82 76 } else if (arg[len] == '=' && narg > 0) {
83 77 /* --flag=value */
84 78 return 1;
85 79 } else if (flags[i].name[1] != '-') {
86 80 /* short flag */
87 81 return 1;
88 82 }
89 83 }
90 84 }
91 85 return 0;
92 86 }
93 87
94 88 /*
95 89 * Parse argv[] and put sensitive flags to opts->args
96 90 */
97 91 static void setcmdserverargs(struct cmdserveropts *opts,
98 92 int argc, const char *argv[])
99 93 {
100 94 size_t i, step;
101 95 opts->argsize = 0;
102 96 for (i = 0, step = 1; i < (size_t)argc; i += step, step = 1) {
103 97 if (!argv[i])
104 98 continue; /* pass clang-analyse */
105 99 if (strcmp(argv[i], "--") == 0)
106 100 break;
107 101 size_t n = testsensitiveflag(argv[i]);
108 102 if (n == 0 || i + n > (size_t)argc)
109 103 continue;
110 104 opts->args = reallocx(opts->args,
111 105 (n + opts->argsize) * sizeof(char *));
112 106 memcpy(opts->args + opts->argsize, argv + i,
113 107 sizeof(char *) * n);
114 108 opts->argsize += n;
115 109 step = n;
116 110 }
117 111 }
118 112
119 113 static void preparesockdir(const char *sockdir)
120 114 {
121 115 int r;
122 116 r = mkdir(sockdir, 0700);
123 117 if (r < 0 && errno != EEXIST)
124 118 abortmsgerrno("cannot create sockdir %s", sockdir);
125 119
126 120 struct stat st;
127 121 r = lstat(sockdir, &st);
128 122 if (r < 0)
129 123 abortmsgerrno("cannot stat %s", sockdir);
130 124 if (!S_ISDIR(st.st_mode))
131 125 abortmsg("cannot create sockdir %s (file exists)", sockdir);
132 126 if (st.st_uid != geteuid() || st.st_mode & 0077)
133 127 abortmsg("insecure sockdir %s", sockdir);
134 128 }
135 129
136 130 static void setcmdserveropts(struct cmdserveropts *opts)
137 131 {
138 132 int r;
139 133 char sockdir[UNIX_PATH_MAX];
140 134 const char *envsockname = getenv("CHGSOCKNAME");
141 135 if (!envsockname) {
142 136 /* by default, put socket file in secure directory
143 137 * (permission of socket file may be ignored on some Unices) */
144 138 const char *tmpdir = getenv("TMPDIR");
145 139 if (!tmpdir)
146 140 tmpdir = "/tmp";
147 141 r = snprintf(sockdir, sizeof(sockdir), "%s/chg%d",
148 142 tmpdir, geteuid());
149 143 if (r < 0 || (size_t)r >= sizeof(sockdir))
150 144 abortmsg("too long TMPDIR (r = %d)", r);
151 145 preparesockdir(sockdir);
152 146 }
153 147
154 148 const char *basename = (envsockname) ? envsockname : sockdir;
155 149 const char *sockfmt = (envsockname) ? "%s" : "%s/server";
156 150 r = snprintf(opts->sockname, sizeof(opts->sockname), sockfmt, basename);
157 151 if (r < 0 || (size_t)r >= sizeof(opts->sockname))
158 152 abortmsg("too long TMPDIR or CHGSOCKNAME (r = %d)", r);
159 153 r = snprintf(opts->initsockname, sizeof(opts->initsockname),
160 154 "%s.%u", opts->sockname, (unsigned)getpid());
161 155 if (r < 0 || (size_t)r >= sizeof(opts->initsockname))
162 156 abortmsg("too long TMPDIR or CHGSOCKNAME (r = %d)", r);
163 157 }
164 158
165 159 static const char *gethgcmd(void)
166 160 {
167 161 static const char *hgcmd = NULL;
168 162 if (!hgcmd) {
169 163 hgcmd = getenv("CHGHG");
170 164 if (!hgcmd || hgcmd[0] == '\0')
171 165 hgcmd = getenv("HG");
172 166 if (!hgcmd || hgcmd[0] == '\0')
173 167 #ifdef HGPATH
174 168 hgcmd = (HGPATH);
175 169 #else
176 170 hgcmd = "hg";
177 171 #endif
178 172 }
179 173 return hgcmd;
180 174 }
181 175
182 176 static void execcmdserver(const struct cmdserveropts *opts)
183 177 {
184 178 const char *hgcmd = gethgcmd();
185 179
186 180 const char *baseargv[] = {
187 181 hgcmd,
188 182 "serve",
189 183 "--cmdserver", "chgunix",
190 184 "--address", opts->initsockname,
191 185 "--daemon-postexec", "chdir:/",
192 186 };
193 187 size_t baseargvsize = sizeof(baseargv) / sizeof(baseargv[0]);
194 188 size_t argsize = baseargvsize + opts->argsize + 1;
195 189
196 190 const char **argv = mallocx(sizeof(char *) * argsize);
197 191 memcpy(argv, baseargv, sizeof(baseargv));
198 192 memcpy(argv + baseargvsize, opts->args, sizeof(char *) * opts->argsize);
199 193 argv[argsize - 1] = NULL;
200 194
201 195 if (putenv("CHGINTERNALMARK=") != 0)
202 196 abortmsgerrno("failed to putenv");
203 197 if (execvp(hgcmd, (char **)argv) < 0)
204 198 abortmsgerrno("failed to exec cmdserver");
205 199 free(argv);
206 200 }
207 201
208 202 /* Retry until we can connect to the server. Give up after some time. */
209 203 static hgclient_t *retryconnectcmdserver(struct cmdserveropts *opts, pid_t pid)
210 204 {
211 205 static const struct timespec sleepreq = {0, 10 * 1000000};
212 206 int pst = 0;
213 207
214 208 debugmsg("try connect to %s repeatedly", opts->initsockname);
215 209
216 210 unsigned int timeoutsec = 60; /* default: 60 seconds */
217 211 const char *timeoutenv = getenv("CHGTIMEOUT");
218 212 if (timeoutenv)
219 213 sscanf(timeoutenv, "%u", &timeoutsec);
220 214
221 215 for (unsigned int i = 0; !timeoutsec || i < timeoutsec * 100; i++) {
222 216 hgclient_t *hgc = hgc_open(opts->initsockname);
223 217 if (hgc) {
224 218 debugmsg("rename %s to %s", opts->initsockname,
225 219 opts->sockname);
226 220 int r = rename(opts->initsockname, opts->sockname);
227 221 if (r != 0)
228 222 abortmsgerrno("cannot rename");
229 223 return hgc;
230 224 }
231 225
232 226 if (pid > 0) {
233 227 /* collect zombie if child process fails to start */
234 228 int r = waitpid(pid, &pst, WNOHANG);
235 229 if (r != 0)
236 230 goto cleanup;
237 231 }
238 232
239 233 nanosleep(&sleepreq, NULL);
240 234 }
241 235
242 236 abortmsg("timed out waiting for cmdserver %s", opts->initsockname);
243 237 return NULL;
244 238
245 239 cleanup:
246 240 if (WIFEXITED(pst)) {
247 241 if (WEXITSTATUS(pst) == 0)
248 242 abortmsg("could not connect to cmdserver "
249 243 "(exited with status 0)");
250 244 debugmsg("cmdserver exited with status %d", WEXITSTATUS(pst));
251 245 exit(WEXITSTATUS(pst));
252 246 } else if (WIFSIGNALED(pst)) {
253 247 abortmsg("cmdserver killed by signal %d", WTERMSIG(pst));
254 248 } else {
255 249 abortmsg("error while waiting for cmdserver");
256 250 }
257 251 return NULL;
258 252 }
259 253
260 254 /* Connect to a cmdserver. Will start a new server on demand. */
261 255 static hgclient_t *connectcmdserver(struct cmdserveropts *opts)
262 256 {
263 257 const char *sockname = opts->redirectsockname[0] ?
264 258 opts->redirectsockname : opts->sockname;
265 259 debugmsg("try connect to %s", sockname);
266 260 hgclient_t *hgc = hgc_open(sockname);
267 261 if (hgc)
268 262 return hgc;
269 263
270 264 /* prevent us from being connected to an outdated server: we were
271 265 * told by a server to redirect to opts->redirectsockname and that
272 266 * address does not work. we do not want to connect to the server
273 267 * again because it will probably tell us the same thing. */
274 268 if (sockname == opts->redirectsockname)
275 269 unlink(opts->sockname);
276 270
277 271 debugmsg("start cmdserver at %s", opts->initsockname);
278 272
279 273 pid_t pid = fork();
280 274 if (pid < 0)
281 275 abortmsg("failed to fork cmdserver process");
282 276 if (pid == 0) {
283 277 execcmdserver(opts);
284 278 } else {
285 279 hgc = retryconnectcmdserver(opts, pid);
286 280 }
287 281
288 282 return hgc;
289 283 }
290 284
291 285 static void killcmdserver(const struct cmdserveropts *opts)
292 286 {
293 287 /* resolve config hash */
294 288 char *resolvedpath = realpath(opts->sockname, NULL);
295 289 if (resolvedpath) {
296 290 unlink(resolvedpath);
297 291 free(resolvedpath);
298 292 }
299 293 }
300 294
301 295 static pid_t pagerpid = 0;
302 296 static pid_t peerpgid = 0;
303 297 static pid_t peerpid = 0;
304 298
305 299 static void forwardsignal(int sig)
306 300 {
307 301 assert(peerpid > 0);
308 302 if (kill(peerpid, sig) < 0)
309 303 abortmsgerrno("cannot kill %d", peerpid);
310 304 debugmsg("forward signal %d", sig);
311 305 }
312 306
313 307 static void forwardsignaltogroup(int sig)
314 308 {
315 309 /* prefer kill(-pgid, sig), fallback to pid if pgid is invalid */
316 310 pid_t killpid = peerpgid > 1 ? -peerpgid : peerpid;
317 311 if (kill(killpid, sig) < 0)
318 312 abortmsgerrno("cannot kill %d", killpid);
319 313 debugmsg("forward signal %d to %d", sig, killpid);
320 314 }
321 315
322 316 static void handlestopsignal(int sig)
323 317 {
324 318 sigset_t unblockset, oldset;
325 319 struct sigaction sa, oldsa;
326 320 if (sigemptyset(&unblockset) < 0)
327 321 goto error;
328 322 if (sigaddset(&unblockset, sig) < 0)
329 323 goto error;
330 324 memset(&sa, 0, sizeof(sa));
331 325 sa.sa_handler = SIG_DFL;
332 326 sa.sa_flags = SA_RESTART;
333 327 if (sigemptyset(&sa.sa_mask) < 0)
334 328 goto error;
335 329
336 330 forwardsignal(sig);
337 331 if (raise(sig) < 0) /* resend to self */
338 332 goto error;
339 333 if (sigaction(sig, &sa, &oldsa) < 0)
340 334 goto error;
341 335 if (sigprocmask(SIG_UNBLOCK, &unblockset, &oldset) < 0)
342 336 goto error;
343 337 /* resent signal will be handled before sigprocmask() returns */
344 338 if (sigprocmask(SIG_SETMASK, &oldset, NULL) < 0)
345 339 goto error;
346 340 if (sigaction(sig, &oldsa, NULL) < 0)
347 341 goto error;
348 342 return;
349 343
350 344 error:
351 345 abortmsgerrno("failed to handle stop signal");
352 346 }
353 347
354 348 static void handlechildsignal(int sig UNUSED_)
355 349 {
356 350 if (peerpid == 0 || pagerpid == 0)
357 351 return;
358 352 /* if pager exits, notify the server with SIGPIPE immediately.
359 353 * otherwise the server won't get SIGPIPE if it does not write
360 354 * anything. (issue5278) */
361 355 if (waitpid(pagerpid, NULL, WNOHANG) == pagerpid)
362 356 kill(peerpid, SIGPIPE);
363 357 }
364 358
365 359 static void setupsignalhandler(const hgclient_t *hgc)
366 360 {
367 361 pid_t pid = hgc_peerpid(hgc);
368 362 if (pid <= 0)
369 363 return;
370 364 peerpid = pid;
371 365
372 366 pid_t pgid = hgc_peerpgid(hgc);
373 367 peerpgid = (pgid <= 1 ? 0 : pgid);
374 368
375 369 struct sigaction sa;
376 370 memset(&sa, 0, sizeof(sa));
377 371 sa.sa_handler = forwardsignaltogroup;
378 372 sa.sa_flags = SA_RESTART;
379 373 if (sigemptyset(&sa.sa_mask) < 0)
380 374 goto error;
381 375
382 376 if (sigaction(SIGHUP, &sa, NULL) < 0)
383 377 goto error;
384 378 if (sigaction(SIGINT, &sa, NULL) < 0)
385 379 goto error;
386 380
387 381 /* terminate frontend by double SIGTERM in case of server freeze */
388 382 sa.sa_handler = forwardsignal;
389 383 sa.sa_flags |= SA_RESETHAND;
390 384 if (sigaction(SIGTERM, &sa, NULL) < 0)
391 385 goto error;
392 386
393 387 /* notify the worker about window resize events */
394 388 sa.sa_flags = SA_RESTART;
395 389 if (sigaction(SIGWINCH, &sa, NULL) < 0)
396 390 goto error;
397 391 /* propagate job control requests to worker */
398 392 sa.sa_handler = forwardsignal;
399 393 sa.sa_flags = SA_RESTART;
400 394 if (sigaction(SIGCONT, &sa, NULL) < 0)
401 395 goto error;
402 396 sa.sa_handler = handlestopsignal;
403 397 sa.sa_flags = SA_RESTART;
404 398 if (sigaction(SIGTSTP, &sa, NULL) < 0)
405 399 goto error;
406 400 /* get notified when pager exits */
407 401 sa.sa_handler = handlechildsignal;
408 402 sa.sa_flags = SA_RESTART;
409 403 if (sigaction(SIGCHLD, &sa, NULL) < 0)
410 404 goto error;
411 405
412 406 return;
413 407
414 408 error:
415 409 abortmsgerrno("failed to set up signal handlers");
416 410 }
417 411
418 412 static void restoresignalhandler()
419 413 {
420 414 struct sigaction sa;
421 415 memset(&sa, 0, sizeof(sa));
422 416 sa.sa_handler = SIG_DFL;
423 417 sa.sa_flags = SA_RESTART;
424 418 if (sigemptyset(&sa.sa_mask) < 0)
425 419 goto error;
426 420
427 421 if (sigaction(SIGHUP, &sa, NULL) < 0)
428 422 goto error;
429 423 if (sigaction(SIGTERM, &sa, NULL) < 0)
430 424 goto error;
431 425 if (sigaction(SIGWINCH, &sa, NULL) < 0)
432 426 goto error;
433 427 if (sigaction(SIGCONT, &sa, NULL) < 0)
434 428 goto error;
435 429 if (sigaction(SIGTSTP, &sa, NULL) < 0)
436 430 goto error;
437 431 if (sigaction(SIGCHLD, &sa, NULL) < 0)
438 432 goto error;
439 433
440 434 /* ignore Ctrl+C while shutting down to make pager exits cleanly */
441 435 sa.sa_handler = SIG_IGN;
442 436 if (sigaction(SIGINT, &sa, NULL) < 0)
443 437 goto error;
444 438
445 439 peerpid = 0;
446 440 return;
447 441
448 442 error:
449 443 abortmsgerrno("failed to restore signal handlers");
450 444 }
451 445
452 446 /* This implementation is based on hgext/pager.py (post 369741ef7253)
453 447 * Return 0 if pager is not started, or pid of the pager */
454 448 static pid_t setuppager(hgclient_t *hgc, const char *const args[],
455 449 size_t argsize)
456 450 {
457 451 const char *pagercmd = hgc_getpager(hgc, args, argsize);
458 452 if (!pagercmd)
459 453 return 0;
460 454
461 455 int pipefds[2];
462 456 if (pipe(pipefds) < 0)
463 457 return 0;
464 458 pid_t pid = fork();
465 459 if (pid < 0)
466 460 goto error;
467 461 if (pid > 0) {
468 462 close(pipefds[0]);
469 463 if (dup2(pipefds[1], fileno(stdout)) < 0)
470 464 goto error;
471 465 if (isatty(fileno(stderr))) {
472 466 if (dup2(pipefds[1], fileno(stderr)) < 0)
473 467 goto error;
474 468 }
475 469 close(pipefds[1]);
476 470 hgc_attachio(hgc); /* reattach to pager */
477 471 return pid;
478 472 } else {
479 473 dup2(pipefds[0], fileno(stdin));
480 474 close(pipefds[0]);
481 475 close(pipefds[1]);
482 476
483 477 int r = execlp("/bin/sh", "/bin/sh", "-c", pagercmd, NULL);
484 478 if (r < 0) {
485 479 abortmsgerrno("cannot start pager '%s'", pagercmd);
486 480 }
487 481 return 0;
488 482 }
489 483
490 484 error:
491 485 close(pipefds[0]);
492 486 close(pipefds[1]);
493 487 abortmsgerrno("failed to prepare pager");
494 488 return 0;
495 489 }
496 490
497 491 static void waitpager(pid_t pid)
498 492 {
499 493 /* close output streams to notify the pager its input ends */
500 494 fclose(stdout);
501 495 fclose(stderr);
502 496 while (1) {
503 497 pid_t ret = waitpid(pid, NULL, 0);
504 498 if (ret == -1 && errno == EINTR)
505 499 continue;
506 500 break;
507 501 }
508 502 }
509 503
510 504 /* Run instructions sent from the server like unlink and set redirect path
511 505 * Return 1 if reconnect is needed, otherwise 0 */
512 506 static int runinstructions(struct cmdserveropts *opts, const char **insts)
513 507 {
514 508 int needreconnect = 0;
515 509 if (!insts)
516 510 return needreconnect;
517 511
518 512 assert(insts);
519 513 opts->redirectsockname[0] = '\0';
520 514 const char **pinst;
521 515 for (pinst = insts; *pinst; pinst++) {
522 516 debugmsg("instruction: %s", *pinst);
523 517 if (strncmp(*pinst, "unlink ", 7) == 0) {
524 518 unlink(*pinst + 7);
525 519 } else if (strncmp(*pinst, "redirect ", 9) == 0) {
526 520 int r = snprintf(opts->redirectsockname,
527 521 sizeof(opts->redirectsockname),
528 522 "%s", *pinst + 9);
529 523 if (r < 0 || r >= (int)sizeof(opts->redirectsockname))
530 524 abortmsg("redirect path is too long (%d)", r);
531 525 needreconnect = 1;
532 526 } else if (strncmp(*pinst, "exit ", 5) == 0) {
533 527 int n = 0;
534 528 if (sscanf(*pinst + 5, "%d", &n) != 1)
535 529 abortmsg("cannot read the exit code");
536 530 exit(n);
537 531 } else if (strcmp(*pinst, "reconnect") == 0) {
538 532 needreconnect = 1;
539 533 } else {
540 534 abortmsg("unknown instruction: %s", *pinst);
541 535 }
542 536 }
543 537 return needreconnect;
544 538 }
545 539
546 540 /*
547 541 * Test whether the command is unsupported or not. This is not designed to
548 542 * cover all cases. But it's fast, does not depend on the server and does
549 543 * not return false positives.
550 544 */
551 545 static int isunsupported(int argc, const char *argv[])
552 546 {
553 547 enum {
554 548 SERVE = 1,
555 549 DAEMON = 2,
556 550 SERVEDAEMON = SERVE | DAEMON,
557 551 TIME = 4,
558 552 };
559 553 unsigned int state = 0;
560 554 int i;
561 555 for (i = 0; i < argc; ++i) {
562 556 if (strcmp(argv[i], "--") == 0)
563 557 break;
564 558 if (i == 0 && strcmp("serve", argv[i]) == 0)
565 559 state |= SERVE;
566 560 else if (strcmp("-d", argv[i]) == 0 ||
567 561 strcmp("--daemon", argv[i]) == 0)
568 562 state |= DAEMON;
569 563 else if (strcmp("--time", argv[i]) == 0)
570 564 state |= TIME;
571 565 }
572 566 return (state & TIME) == TIME ||
573 567 (state & SERVEDAEMON) == SERVEDAEMON;
574 568 }
575 569
576 570 static void execoriginalhg(const char *argv[])
577 571 {
578 572 debugmsg("execute original hg");
579 573 if (execvp(gethgcmd(), (char **)argv) < 0)
580 574 abortmsgerrno("failed to exec original hg");
581 575 }
582 576
583 577 int main(int argc, const char *argv[], const char *envp[])
584 578 {
585 579 if (getenv("CHGDEBUG"))
586 580 enabledebugmsg();
587 581
588 582 if (!getenv("HGPLAIN") && isatty(fileno(stderr)))
589 583 enablecolor();
590 584
591 585 if (getenv("CHGINTERNALMARK"))
592 586 abortmsg("chg started by chg detected.\n"
593 587 "Please make sure ${HG:-hg} is not a symlink or "
594 588 "wrapper to chg. Alternatively, set $CHGHG to the "
595 589 "path of real hg.");
596 590
597 591 if (isunsupported(argc - 1, argv + 1))
598 592 execoriginalhg(argv);
599 593
600 594 struct cmdserveropts opts;
601 595 initcmdserveropts(&opts);
602 596 setcmdserveropts(&opts);
603 597 setcmdserverargs(&opts, argc, argv);
604 598
605 599 if (argc == 2) {
606 600 if (strcmp(argv[1], "--kill-chg-daemon") == 0) {
607 601 killcmdserver(&opts);
608 602 return 0;
609 603 }
610 604 }
611 605
612 606 hgclient_t *hgc;
613 607 size_t retry = 0;
614 608 while (1) {
615 609 hgc = connectcmdserver(&opts);
616 610 if (!hgc)
617 611 abortmsg("cannot open hg client");
618 612 hgc_setenv(hgc, envp);
619 613 const char **insts = hgc_validate(hgc, argv + 1, argc - 1);
620 614 int needreconnect = runinstructions(&opts, insts);
621 615 free(insts);
622 616 if (!needreconnect)
623 617 break;
624 618 hgc_close(hgc);
625 619 if (++retry > 10)
626 620 abortmsg("too many redirections.\n"
627 621 "Please make sure %s is not a wrapper which "
628 622 "changes sensitive environment variables "
629 623 "before executing hg. If you have to use a "
630 624 "wrapper, wrap chg instead of hg.",
631 625 gethgcmd());
632 626 }
633 627
634 628 setupsignalhandler(hgc);
635 629 pagerpid = setuppager(hgc, argv + 1, argc - 1);
636 630 int exitcode = hgc_runcommand(hgc, argv + 1, argc - 1);
637 631 restoresignalhandler();
638 632 hgc_close(hgc);
639 633 freecmdserveropts(&opts);
640 634 if (pagerpid)
641 635 waitpager(pagerpid);
642 636
643 637 return exitcode;
644 638 }
General Comments 0
You need to be logged in to leave comments. Login now