1 From 090026f33031c1b46dfe3e2e077c6cb0aa149378 Mon Sep 17 00:00:00 2001
2 From: David Teigland <teigland@redhat.com>
3 Date: Wed, 12 Feb 2014 12:09:10 -0600
4 Subject: dlm_tool: fix status printing in libdlmcontrol
6 When a node was both a startup node and a normal node,
7 then status would segfault.
9 Signed-off-by: David Teigland <teigland@redhat.com>
11 diff --git a/dlm_controld/lib.c b/dlm_controld/lib.c
12 index 961626f..efb74e0 100644
13 --- a/dlm_controld/lib.c
14 +++ b/dlm_controld/lib.c
15 @@ -337,12 +337,19 @@ int dlmc_print_status(uint32_t flags)
16 struct dlmc_state *st;
17 char maxstr[DLMC_STATE_MAXSTR];
18 char maxbin[DLMC_STATE_MAXBIN];
20 - int all_count, node_count, fence_count;
21 - int all_ids[MAX_SORT], node_ids[MAX_SORT], fence_ids[MAX_SORT];
22 - char *node_lines[MAX_SORT], *fence_lines[MAX_SORT];
23 - char *node_line, *fence_line;
27 + int all_count, node_count, fence_count, startup_count;
28 + int all_ids[MAX_SORT];
29 + int node_ids[MAX_SORT];
30 + int fence_ids[MAX_SORT];
31 + int startup_ids[MAX_SORT];
32 + char *node_lines[MAX_SORT];
33 + char *fence_lines[MAX_SORT];
40 init_header(&h, DLMC_CMD_DUMP_STATUS, NULL, 0);
41 @@ -363,14 +370,15 @@ int dlmc_print_status(uint32_t flags)
51 memset(&all_ids, 0, sizeof(all_ids));
52 memset(&node_ids, 0, sizeof(node_ids));
53 memset(&fence_ids, 0, sizeof(fence_ids));
54 + memset(&startup_ids, 0, sizeof(startup_ids));
55 memset(node_lines, 0, sizeof(node_lines));
56 memset(fence_lines, 0, sizeof(fence_lines));
58 @@ -402,9 +410,11 @@ int dlmc_print_status(uint32_t flags)
59 print_daemon(st, str, bin, flags);
62 - case DLMC_STATE_DAEMON_NODE:
63 case DLMC_STATE_STARTUP_NODE:
64 + startup_ids[startup_count++] = st->nodeid;
67 + case DLMC_STATE_DAEMON_NODE:
68 if (flags & DLMC_STATUS_VERBOSE) {
69 printf("nodeid %d\n", st->nodeid);
70 print_str(str, st->str_len);
71 @@ -426,7 +436,7 @@ int dlmc_print_status(uint32_t flags)
72 all_ids[all_count++] = st->nodeid;
74 node_ids[node_count] = st->nodeid;
75 - node_lines[node_count++] = node_line;
76 + node_lines[node_count] = node_line;
80 @@ -450,13 +460,39 @@ int dlmc_print_status(uint32_t flags)
82 qsort(all_ids, all_count, sizeof(int), nodeid_compare);
84 + /* don't free any node_lines in this startup loop because we are just
85 + borrowing them; they are needed in the real node loop below. */
87 + if (startup_count) {
88 + for (i = 0; i < startup_count; i++) {
90 + for (j = 0; j < node_count; j++) {
91 + if (startup_ids[i] != node_ids[j])
95 + printf("startup node %d\n", st->nodeid);
97 + printf("startup %s", node_lines[j]);
101 + printf("startup node %d\n", st->nodeid);
105 if (all_count && fence_count) {
106 for (i = 0; i < all_count; i++) {
107 for (j = 0; j < fence_count; j++) {
108 if (all_ids[i] != fence_ids[j])
110 - printf("%s", fence_lines[j]);
111 - free(fence_lines[j]);
112 + if (!fence_lines[j]) {
113 + printf("fence %d no data\n", fence_ids[j]);
115 + printf("%s", fence_lines[j]);
116 + free(fence_lines[j]);
117 + fence_lines[j] = NULL;
122 @@ -467,8 +503,13 @@ int dlmc_print_status(uint32_t flags)
123 for (j = 0; j < node_count; j++) {
124 if (all_ids[i] != node_ids[j])
126 - printf("%s", node_lines[j]);
127 - free(node_lines[j]);
128 + if (!node_lines[j]) {
129 + printf("node %d no data\n", node_ids[j]);
131 + printf("%s", node_lines[j]);
132 + free(node_lines[j]);
133 + node_lines[j] = NULL;