Process the INFO output from masters. */
| 2509 | |
| 2510 | /* Process the INFO output from masters. */ |
| 2511 | void sentinelRefreshInstanceInfo(sentinelRedisInstance *ri, const char *info) { |
| 2512 | sds *lines; |
| 2513 | int numlines, j; |
| 2514 | int role = 0; |
| 2515 | |
| 2516 | /* cache full INFO output for instance */ |
| 2517 | sdsfree(ri->info); |
| 2518 | ri->info = sdsnew(info); |
| 2519 | |
| 2520 | /* The following fields must be reset to a given value in the case they |
| 2521 | * are not found at all in the INFO output. */ |
| 2522 | ri->master_link_down_time = 0; |
| 2523 | |
| 2524 | /* Process line by line. */ |
| 2525 | lines = sdssplitlen(info,strlen(info),"\r\n",2,&numlines); |
| 2526 | for (j = 0; j < numlines; j++) { |
| 2527 | sentinelRedisInstance *slave; |
| 2528 | sds l = lines[j]; |
| 2529 | |
| 2530 | /* run_id:<40 hex chars>*/ |
| 2531 | if (sdslen(l) >= 47 && !memcmp(l,"run_id:",7)) { |
| 2532 | if (ri->runid == NULL) { |
| 2533 | ri->runid = sdsnewlen(l+7,40); |
| 2534 | } else { |
| 2535 | if (strncmp(ri->runid,l+7,40) != 0) { |
| 2536 | sentinelEvent(LL_NOTICE,"+reboot",ri,"%@"); |
| 2537 | sdsfree(ri->runid); |
| 2538 | ri->runid = sdsnewlen(l+7,40); |
| 2539 | } |
| 2540 | } |
| 2541 | } |
| 2542 | |
| 2543 | /* old versions: slave0:<ip>,<port>,<state> |
| 2544 | * new versions: slave0:ip=127.0.0.1,port=9999,... */ |
| 2545 | if ((ri->flags & SRI_MASTER) && |
| 2546 | sdslen(l) >= 7 && |
| 2547 | !memcmp(l,"slave",5) && isdigit(l[5])) |
| 2548 | { |
| 2549 | char *ip, *port, *end; |
| 2550 | |
| 2551 | if (strstr(l,"ip=") == NULL) { |
| 2552 | /* Old format. */ |
| 2553 | ip = strchr(l,':'); if (!ip) continue; |
| 2554 | ip++; /* Now ip points to start of ip address. */ |
| 2555 | port = strchr(ip,','); if (!port) continue; |
| 2556 | *port = '\0'; /* nul term for easy access. */ |
| 2557 | port++; /* Now port points to start of port number. */ |
| 2558 | end = strchr(port,','); if (!end) continue; |
| 2559 | *end = '\0'; /* nul term for easy access. */ |
| 2560 | } else { |
| 2561 | /* New format. */ |
| 2562 | ip = strstr(l,"ip="); if (!ip) continue; |
| 2563 | ip += 3; /* Now ip points to start of ip address. */ |
| 2564 | port = strstr(l,"port="); if (!port) continue; |
| 2565 | port += 5; /* Now port points to start of port number. */ |
| 2566 | /* Nul term both fields for easy access. */ |
| 2567 | end = strchr(ip,','); if (end) *end = '\0'; |
| 2568 | end = strchr(port,','); if (end) *end = '\0'; |
no test coverage detected