static int ringstatusget_do (char *interface_name) { cs_error_t result; corosync_cfg_handle_t handle; unsigned int interface_count; char **interface_names; char **interface_status; unsigned int i; unsigned int nodeid; int rc = 0; printf ("Printing ring status.\n"); result = corosync_cfg_initialize (&handle, NULL); printf ("xxx 47500: tools/corosync-cfgtool.c After corosync_cfg_initialize...\n"); if (result != CS_OK) { printf ("Could not initialize corosync configuration API error %d\n", result); exit (1); } result = corosync_cfg_local_get(handle, &nodeid); if (result != CS_OK) { printf ("Could not get the local node id, the error is: %d\n", result); } else { printf ("Local node ID %d\n", nodeid); } result = corosync_cfg_ring_status_get (handle, &interface_names, &interface_status, &interface_count); if (result != CS_OK) { printf ("Could not get the ring status, the error is: %d\n", result); } else { for (i = 0; i < interface_count; i++) { if ( (interface_name && (interface_name[0]=='\0' || strcasecmp (interface_name, interface_names[i]) == 0)) || !interface_name ) { printf ("RING ID %d\n", i); printf ("\tid\t= %s\n", interface_names[i]); printf ("\tstatus\t= %s\n", interface_status[i]); if (strstr(interface_status[i], "FAULTY")) { rc = 1; } } } } (void)corosync_cfg_finalize (handle); return rc; }
static void ringstatusget_do (void) { cs_error_t result; corosync_cfg_handle_t handle; unsigned int interface_count; char **interface_names; char **interface_status; unsigned int i; unsigned int nodeid; printf ("Printing ring 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 = corosync_cfg_local_get(handle, &nodeid); if (result != CS_OK) { printf ("Could not get the local node id, the error is: %d\n", result); } else { printf ("Local node ID %d\n", nodeid); } result = corosync_cfg_ring_status_get (handle, &interface_names, &interface_status, &interface_count); if (result != CS_OK) { printf ("Could not get the ring status, the error is: %d\n", result); } else { for (i = 0; i < interface_count; i++) { printf ("RING ID %d\n", i); printf ("\tid\t= %s\n", interface_names[i]); printf ("\tstatus\t= %s\n", interface_status[i]); } } (void)corosync_cfg_finalize (handle); }
static int linkstatusget_do (char *interface_name, int brief) { cs_error_t result; corosync_cfg_handle_t handle; unsigned int interface_count; char **interface_names; char **interface_status; unsigned int i; unsigned int nodeid; int rc = 0; int len, s = 0, t; 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 = corosync_cfg_local_get(handle, &nodeid); if (result != CS_OK) { printf ("Could not get the local node id, the error is: %d\n", result); } else { printf ("Local node ID %u\n", nodeid); } result = corosync_cfg_ring_status_get (handle, &interface_names, &interface_status, &interface_count); if (result != CS_OK) { printf ("Could not get the link status, the error is: %d\n", result); } else { for (i = 0; i < interface_count; i++) { s = 0; if ( (interface_name && interface_names[i][0] != '\0' && (interface_name[0]=='\0' || strcasecmp (interface_name, interface_names[i]) == 0)) || !interface_name ) { /* * Interface_name is "<linkid> <IP address>" * separate them out */ char *space = strchr(interface_names[i], ' '); if (!space) { continue; } *space = '\0'; printf ("LINK ID %s\n", interface_names[i]); printf ("\taddr\t= %s\n", space+1); if((!brief) && (strcmp(interface_status[i], "OK") != 0) && (!strstr(interface_status[i], "FAULTY"))) { len = strlen(interface_status[i]); printf ("\tstatus:\n"); while(s < len) { t = interface_status[i][s] - '0'; printf("\t\tnode %d:\t", s++); printf("link enabled:%d\t", t&1? 1 : 0); printf("link connected:%d\n", t&2? 1: 0); } } else { printf ("\tstatus\t= %s\n", interface_status[i]); if (strstr(interface_status[i], "FAULTY")) { rc = 1; } } } } for (i = 0; i < interface_count; i++) { free(interface_status[i]); free(interface_names[i]); } free(interface_status); free(interface_names); } (void)corosync_cfg_finalize (handle); return rc; }