]> git.pld-linux.org Git - packages/dlm.git/blob - fix_status_printing.patch
rel 2; fix dlm_tool status segfaulting
[packages/dlm.git] / fix_status_printing.patch
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
5
6 When a node was both a startup node and a normal node,
7 then status would segfault.
8
9 Signed-off-by: David Teigland <teigland@redhat.com>
10
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];
19 -       char *str, *bin;
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;
24 -       int fd, rv, off;
25 +       char *str;
26 +       char *bin;
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];
34 +       char *node_line;
35 +       char *fence_line;
36 +       int found_node;
37 +       int fd, rv;
38         int i, j;
39  
40         init_header(&h, DLMC_CMD_DUMP_STATUS, NULL, 0);
41 @@ -363,14 +370,15 @@ int dlmc_print_status(uint32_t flags)
42         st = &state;
43         str = maxstr;
44         bin = maxbin;
45 -       off = 0;
46  
47         all_count = 0;
48         node_count = 0;
49         fence_count = 0;
50 +       startup_count = 0;
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));
57  
58 @@ -402,9 +410,11 @@ int dlmc_print_status(uint32_t flags)
59                         print_daemon(st, str, bin, flags);
60                         break;
61  
62 -               case DLMC_STATE_DAEMON_NODE:
63                 case DLMC_STATE_STARTUP_NODE:
64 +                       startup_ids[startup_count++] = st->nodeid;
65 +                       break;
66  
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;
73  
74                                 node_ids[node_count] = st->nodeid;
75 -                               node_lines[node_count++] = node_line;
76 +                               node_lines[node_count] = node_line;
77                                 node_count++;
78  
79                                 if (!fence_line[0]) {
80 @@ -450,13 +460,39 @@ int dlmc_print_status(uint32_t flags)
81         if (all_count)
82                 qsort(all_ids, all_count, sizeof(int), nodeid_compare);
83  
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. */
86 +
87 +       if (startup_count) {
88 +               for (i = 0; i < startup_count; i++) {
89 +                       found_node = 0;
90 +                       for (j = 0; j < node_count; j++) {
91 +                               if (startup_ids[i] != node_ids[j])
92 +                                       continue;
93 +                               found_node = 1;
94 +                               if (!node_lines[j])
95 +                                       printf("startup node %d\n", st->nodeid);
96 +                               else
97 +                                       printf("startup %s", node_lines[j]);
98 +                               break;
99 +                       }
100 +                       if (!found_node)
101 +                               printf("startup node %d\n", st->nodeid);
102 +               }
103 +       }
104 +
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])
109                                         continue;
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]);
114 +                               } else {
115 +                                       printf("%s", fence_lines[j]);
116 +                                       free(fence_lines[j]);
117 +                                       fence_lines[j] = NULL;
118 +                               }
119                                 break;
120                         }
121                 }
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])
125                                         continue;
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]);
130 +                               } else {
131 +                                       printf("%s", node_lines[j]);
132 +                                       free(node_lines[j]);
133 +                                       node_lines[j] = NULL;
134 +                               }
135                                 break;
136                         }
137                 }
138 -- 
139 cgit v0.10.1
140
This page took 0.082593 seconds and 3 git commands to generate.