Skip to content

Commit

Permalink
cfgtool: Fix error code as described in MP
Browse files Browse the repository at this point in the history
If all links are connected 0 is returned to the shell, otherwise it's
error code 1.

Signed-off-by: Hideo Yamauchi <renayama19661014@ybb.ne.jp>
Reviewed-by: Jan Friesse <jfriesse@redhat.com>
  • Loading branch information
HideoYamauchi authored and jfriesse committed Mar 30, 2020
1 parent c631951 commit 0d0febb
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions tools/corosync-cfgtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,32 @@ linkstatusget_do (char *interface_name, int brief)
int rc = 0;
int len, s = 0, t;
char stat_ch;
char *str;
totem_transport_t transport_number = TOTEM_TRANSPORT_KNET;

printf ("Printing link status.\n");
result = corosync_cfg_initialize (&handle, NULL);
if (result != CS_OK) {
printf ("Could not initialize corosync configuration API error %d\n", result);
exit (1);
}

result = cmap_initialize (&cmap_handle);
if (result != CS_OK) {
printf ("Could not initialize corosync cmap API error %d\n", result);
exit (1);
}

result = cmap_get_string(cmap_handle, "totem.transport", &str);
if (result == CS_OK) {
if (strcmp (str, "udpu") == 0) {
transport_number = TOTEM_TRANSPORT_UDPU;
}
if (strcmp (str, "udp") == 0) {
transport_number = TOTEM_TRANSPORT_UDP;
}
free(str);
}

/* Get a list of nodes. We do it this way rather than using votequorum as cfgtool
* needs to be independent of quorum type
*/
Expand Down Expand Up @@ -192,14 +205,21 @@ linkstatusget_do (char *interface_name, int brief)
* UDP(U) interface_status is always OK and doesn't contain
* detailed information (only knet does).
*/
if ((!brief) && (strcmp(interface_status[i], "OK") != 0)) {
if ((!brief) && (transport_number == TOTEM_TRANSPORT_KNET)) {
len = strlen(interface_status[i]);
printf ("\tstatus:\n");
while (s < len) {
nodeid = nodeid_list[s];
printf("\t\tnodeid %2d:\t", nodeid);
stat_ch = interface_status[i][s];

/* Set return code to 1 if status is not localhost or connected. */
if (rc == 0) {
if ((stat_ch != 'n') && (stat_ch != '3')) {
rc = 1;
}
}

if (stat_ch >= '0' && stat_ch <= '9') {
t = stat_ch - '0';

Expand Down Expand Up @@ -231,6 +251,19 @@ linkstatusget_do (char *interface_name, int brief)
}
} else {
printf ("\tstatus\t= %s\n", interface_status[i]);

/* Set return code to 1 if status is not localhost or connected. */
if ((rc == 0) && (transport_number == TOTEM_TRANSPORT_KNET)) {
len = strlen(interface_status[i]);
while (s < len) {
stat_ch = interface_status[i][s];
if ((stat_ch != 'n') && (stat_ch != '3')) {
rc = 1;
break;
}
s++;
}
}
}
}
}
Expand Down

0 comments on commit 0d0febb

Please sign in to comment.