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