Ver Fonte

cfgtool: Fix error code as described in MP

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>
Hideo Yamauchi há 5 anos atrás
pai
commit
0d0febbc94
1 ficheiros alterados com 35 adições e 2 exclusões
  1. 35 2
      tools/corosync-cfgtool.c

+ 35 - 2
tools/corosync-cfgtool.c

@@ -106,6 +106,8 @@ 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);
@@ -113,12 +115,23 @@ linkstatusget_do (char *interface_name, int brief)
 		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
 	 */
@@ -192,7 +205,7 @@ 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) {
@@ -200,6 +213,13 @@ linkstatusget_do (char *interface_name, int brief)
 						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';
 
@@ -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++;
+						}
+					}
 				}
 			}
 		}