##// END OF EJS Templates
chgserver: add an explicit "reconnect" instruction to validate...
Jun Wu -
r28535:aa082a81 default
parent child Browse files
Show More
@@ -444,9 +444,14 b' error:'
444 444 abortmsg("failed to prepare pager (errno = %d)", errno);
445 445 }
446 446
447 /* Run instructions sent from the server like unlink and set redirect path */
448 static void runinstructions(struct cmdserveropts *opts, const char **insts)
447 /* Run instructions sent from the server like unlink and set redirect path
448 * Return 1 if reconnect is needed, otherwise 0 */
449 static int runinstructions(struct cmdserveropts *opts, const char **insts)
449 450 {
451 int needreconnect = 0;
452 if (!insts)
453 return needreconnect;
454
450 455 assert(insts);
451 456 opts->redirectsockname[0] = '\0';
452 457 const char **pinst;
@@ -460,15 +465,19 b' static void runinstructions(struct cmdse'
460 465 "%s", *pinst + 9);
461 466 if (r < 0 || r >= (int)sizeof(opts->redirectsockname))
462 467 abortmsg("redirect path is too long (%d)", r);
468 needreconnect = 1;
463 469 } else if (strncmp(*pinst, "exit ", 5) == 0) {
464 470 int n = 0;
465 471 if (sscanf(*pinst + 5, "%d", &n) != 1)
466 472 abortmsg("cannot read the exit code");
467 473 exit(n);
474 } else if (strcmp(*pinst, "reconnect") == 0) {
475 needreconnect = 1;
468 476 } else {
469 477 abortmsg("unknown instruction: %s", *pinst);
470 478 }
471 479 }
480 return needreconnect;
472 481 }
473 482
474 483 /*
@@ -542,10 +551,10 b' int main(int argc, const char *argv[], c'
542 551 abortmsg("cannot open hg client");
543 552 hgc_setenv(hgc, envp);
544 553 const char **insts = hgc_validate(hgc, argv + 1, argc - 1);
545 if (insts == NULL)
554 int needreconnect = runinstructions(&opts, insts);
555 free(insts);
556 if (!needreconnect)
546 557 break;
547 runinstructions(&opts, insts);
548 free(insts);
549 558 hgc_close(hgc);
550 559 if (++retry > 10)
551 560 abortmsg("too many redirections.\n"
@@ -478,8 +478,8 b' pid_t hgc_peerpid(const hgclient_t *hgc)'
478 478 *
479 479 * @return - NULL, the server believes it can handle our request, or does not
480 480 * support "validate" command.
481 * - a list of strings, the server cannot handle our request and it
482 * sent instructions telling us how to fix the issue. See
481 * - a list of strings, the server probably cannot handle our request
482 * and it sent instructions telling us what to do next. See
483 483 * chgserver.py for possible instruction formats.
484 484 * the list should be freed by the caller.
485 485 * the last string is guaranteed to be NULL.
@@ -427,10 +427,16 b' class chgcmdserver(commandserver.server)'
427 427 An instruction string could be either:
428 428 - "unlink $path", the client should unlink the path to stop the
429 429 outdated server.
430 - "redirect $path", the client should try to connect to another
431 server instead.
430 - "redirect $path", the client should attempt to connect to $path
431 first. If it does not work, start a new server. It implies
432 "reconnect".
432 433 - "exit $n", the client should exit directly with code n.
433 434 This may happen if we cannot parse the config.
435 - "reconnect", the client should close the connection and
436 reconnect.
437 If neither "reconnect" nor "redirect" is included in the instruction
438 list, the client can continue with this server after completing all
439 the instructions.
434 440 """
435 441 args = self._readlist()
436 442 try:
@@ -445,6 +451,7 b' class chgcmdserver(commandserver.server)'
445 451 if newhash.mtimehash != self.hashstate.mtimehash:
446 452 addr = _hashaddress(self.baseaddress, self.hashstate.confighash)
447 453 insts.append('unlink %s' % addr)
454 insts.append('reconnect')
448 455 if newhash.confighash != self.hashstate.confighash:
449 456 addr = _hashaddress(self.baseaddress, newhash.confighash)
450 457 insts.append('redirect %s' % addr)
General Comments 0
You need to be logged in to leave comments. Login now