Print this page
10130 smatch fixes for usr/src/cmd/fm
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/fm/fmdump/common/fault.c
+++ new/usr/src/cmd/fm/fmdump/common/fault.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
23 - * Copyright (c) 2017, Joyent, Inc. All rights reserved.
23 + * Copyright (c) 2018, Joyent, Inc.
24 24 */
25 25
26 26 #include <fmdump.h>
27 27 #include <stdio.h>
28 28 #include <strings.h>
29 29
30 30 /*ARGSUSED*/
31 31 static int
32 32 flt_short(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
33 33 {
34 34 char buf[32], str[32];
35 35 char *class = NULL, *uuid = "-", *code = "-";
36 36
37 37 static const struct {
38 38 const char *class;
39 39 const char *tag;
40 40 } tags[] = {
41 41 { FM_LIST_SUSPECT_CLASS, "Diagnosed" },
42 42 { FM_LIST_REPAIRED_CLASS, "Repaired" },
43 43 { FM_LIST_RESOLVED_CLASS, "Resolved" },
44 44 { FM_LIST_UPDATED_CLASS, "Updated" },
45 45 { FM_LIST_ISOLATED_CLASS, "Isolated" },
46 46 };
47 47
48 48 (void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_UUID, &uuid);
49 49 (void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_DIAG_CODE, &code);
50 50
51 51 (void) nvlist_lookup_string(rp->rec_nvl, FM_CLASS, &class);
52 52 if (class != NULL) {
53 53 int i;
54 54
55 55 for (i = 0; i < sizeof (tags) / sizeof (tags[0]); i++) {
56 56 if (strcmp(class, tags[i].class) == 0) {
57 57 (void) snprintf(str, sizeof (str), "%s %s",
58 58 code, tags[i].tag);
59 59 code = str;
60 60 break;
61 61 }
62 62 }
63 63 }
64 64
65 65 fmdump_printf(fp, "%-20s %-32s %s\n",
66 66 fmdump_date(buf, sizeof (buf), rp), uuid, code);
67 67
68 68 return (0);
69 69 }
70 70
71 71 static int
72 72 flt_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
73 73 {
74 74 uint_t i, size = 0;
75 75 nvlist_t **nva;
76 76 uint8_t *ba;
77 77
78 78 (void) flt_short(lp, rp, fp);
79 79 (void) nvlist_lookup_uint32(rp->rec_nvl, FM_SUSPECT_FAULT_SZ, &size);
80 80
81 81 if (size != 0) {
82 82 (void) nvlist_lookup_nvlist_array(rp->rec_nvl,
83 83 FM_SUSPECT_FAULT_LIST, &nva, &size);
84 84 (void) nvlist_lookup_uint8_array(rp->rec_nvl,
85 85 FM_SUSPECT_FAULT_STATUS, &ba, &size);
86 86 }
87 87
88 88 for (i = 0; i < size; i++) {
89 89 char *class = NULL, *rname = NULL, *aname = NULL, *fname = NULL;
90 90 char *loc = NULL;
91 91 nvlist_t *fru, *asru, *rsrc;
92 92 uint8_t pct = 0;
93 93
94 94 (void) nvlist_lookup_uint8(nva[i], FM_FAULT_CERTAINTY, &pct);
95 95 (void) nvlist_lookup_string(nva[i], FM_CLASS, &class);
96 96
97 97 if (nvlist_lookup_nvlist(nva[i], FM_FAULT_FRU, &fru) == 0)
98 98 fname = fmdump_nvl2str(fru);
99 99
100 100 if (nvlist_lookup_nvlist(nva[i], FM_FAULT_ASRU, &asru) == 0)
101 101 aname = fmdump_nvl2str(asru);
102 102
103 103 if (nvlist_lookup_nvlist(nva[i], FM_FAULT_RESOURCE, &rsrc) == 0)
104 104 rname = fmdump_nvl2str(rsrc);
105 105
106 106 if (nvlist_lookup_string(nva[i], FM_FAULT_LOCATION, &loc)
107 107 == 0) {
108 108 if (fname && strncmp(fname, FM_FMRI_LEGACY_HC_PREFIX,
109 109 sizeof (FM_FMRI_LEGACY_HC_PREFIX)) == 0)
110 110 loc = fname + sizeof (FM_FMRI_LEGACY_HC_PREFIX);
111 111 }
112 112
113 113
114 114 fmdump_printf(fp, " %3u%% %s",
115 115 pct, class ? class : "-");
116 116
117 117 if (ba[i] & FM_SUSPECT_FAULTY)
118 118 fmdump_printf(fp, "\n\n");
119 119 else if (ba[i] & FM_SUSPECT_NOT_PRESENT)
120 120 fmdump_printf(fp, "\tRemoved\n\n");
121 121 else if (ba[i] & FM_SUSPECT_REPLACED)
122 122 fmdump_printf(fp, "\tReplaced\n\n");
123 123 else if (ba[i] & FM_SUSPECT_REPAIRED)
124 124 fmdump_printf(fp, "\tRepair Attempted\n\n");
125 125 else if (ba[i] & FM_SUSPECT_ACQUITTED)
126 126 fmdump_printf(fp, "\tAcquitted\n\n");
127 127 else
128 128 fmdump_printf(fp, "\n\n");
129 129
130 130 fmdump_printf(fp, " Problem in: %s\n",
131 131 rname ? rname : "-");
132 132
133 133 fmdump_printf(fp, " Affects: %s\n",
134 134 aname ? aname : "-");
135 135
136 136 fmdump_printf(fp, " FRU: %s\n",
137 137 fname ? fname : "-");
138 138
139 139 fmdump_printf(fp, " Location: %s\n\n",
140 140 loc ? loc : "-");
141 141
142 142 free(fname);
143 143 free(aname);
144 144 free(rname);
145 145 }
146 146
147 147 return (0);
148 148 }
149 149
150 150 static int
151 151 flt_verb23_cmn(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp,
152 152 nvlist_prtctl_t pctl)
153 153 {
154 154 const struct fmdump_fmt *efp = &fmdump_err_ops.do_formats[FMDUMP_VERB1];
155 155 const struct fmdump_fmt *ffp = &fmdump_flt_ops.do_formats[FMDUMP_VERB2];
156 156 uint_t i;
157 157 char buf[32], str[32];
158 158 char *class = NULL, *uuid = "-", *code = "-";
159 159
160 160 (void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_UUID, &uuid);
161 161 (void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_DIAG_CODE, &code);
162 162
163 163 (void) nvlist_lookup_string(rp->rec_nvl, FM_CLASS, &class);
164 164 if (class != NULL && strcmp(class, FM_LIST_REPAIRED_CLASS) == 0) {
165 165 (void) snprintf(str, sizeof (str), "%s %s", code, "Repaired");
166 166 code = str;
167 167 }
168 168 if (class != NULL && strcmp(class, FM_LIST_RESOLVED_CLASS) == 0) {
169 169 (void) snprintf(str, sizeof (str), "%s %s", code, "Resolved");
170 170 code = str;
171 171 }
172 172 if (class != NULL && strcmp(class, FM_LIST_UPDATED_CLASS) == 0) {
173 173 (void) snprintf(str, sizeof (str), "%s %s", code, "Updated");
174 174 code = str;
175 175 }
↓ open down ↓ |
142 lines elided |
↑ open up ↑ |
176 176
177 177 fmdump_printf(fp, "%s\n", ffp->do_hdr);
178 178 fmdump_printf(fp, "%-20s.%9.9llu %-32s %s\n",
179 179 fmdump_year(buf, sizeof (buf), rp), rp->rec_nsec, uuid, code);
180 180
181 181 if (rp->rec_nrefs != 0)
182 182 fmdump_printf(fp, "\n %s\n", efp->do_hdr);
183 183
184 184 for (i = 0; i < rp->rec_nrefs; i++) {
185 185 fmdump_printf(fp, " ");
186 - efp->do_func(lp, &rp->rec_xrefs[i], fp);
186 + (void) efp->do_func(lp, &rp->rec_xrefs[i], fp);
187 187 }
188 188
189 189 fmdump_printf(fp, "\n");
190 190 if (pctl)
191 191 nvlist_prt(rp->rec_nvl, pctl);
192 192 else
193 193 nvlist_print(fp, rp->rec_nvl);
194 194 fmdump_printf(fp, "\n");
195 195
196 196 return (0);
197 197 }
198 198
199 199 static int
200 200 flt_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
201 201 {
202 202 return (flt_verb23_cmn(lp, rp, fp, NULL));
203 203 }
204 204
205 205
206 206 static int
207 207 flt_pretty(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
208 208 {
209 209 nvlist_prtctl_t pctl;
210 210 int rc;
211 211
212 212 if ((pctl = nvlist_prtctl_alloc()) != NULL) {
213 213 nvlist_prtctl_setdest(pctl, fp);
214 214 nvlist_prtctlop_nvlist(pctl, fmdump_render_nvlist, NULL);
215 215 }
216 216
217 217 rc = flt_verb23_cmn(lp, rp, fp, pctl);
218 218
219 219 nvlist_prtctl_free(pctl);
220 220 return (rc);
221 221 }
222 222
223 223 /*
224 224 * There is a lack of uniformity in how the various entries in our diagnosis
225 225 * are terminated. Some end with one newline, others with two. This makes the
226 226 * output of fmdump -m look a bit ugly. Therefore we postprocess the message
227 227 * before printing it, removing consecutive occurences of newlines.
228 228 */
229 229 static void
230 230 postprocess_msg(char *msg)
231 231 {
232 232 int i = 0, j = 0;
233 233 char *buf;
234 234
235 235 if ((buf = malloc(strlen(msg) + 1)) == NULL)
236 236 return;
237 237
238 238 buf[j++] = msg[i++];
239 239 for (i = 1; i < strlen(msg); i++) {
240 240 if (!(msg[i] == '\n' && msg[i - 1] == '\n'))
241 241 buf[j++] = msg[i];
242 242 }
243 243 buf[j] = '\0';
244 244 (void) strncpy(msg, buf, j+1);
245 245 free(buf);
246 246 }
247 247
248 248 /*ARGSUSED*/
249 249 static int
250 250 flt_msg(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
251 251 {
252 252 char *msg, *uuid = "-", *code = "-";
253 253
254 254 if ((msg = fmd_msg_gettext_nv(g_msg, NULL, rp->rec_nvl)) == NULL) {
255 255 (void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_UUID,
256 256 &uuid);
257 257 (void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_DIAG_CODE,
258 258 &code);
259 259 (void) fprintf(stderr, "%s: failed to format message for "
260 260 "diagcode %s, event %s: %s\n\n", g_pname, code, uuid,
261 261 strerror(errno));
262 262 g_errs++;
263 263 } else {
264 264 postprocess_msg(msg);
265 265 fmdump_printf(fp, "%s\n", msg);
266 266 free(msg);
267 267 }
268 268
269 269 return (0);
270 270 }
271 271
272 272 const fmdump_ops_t fmdump_flt_ops = {
273 273 "fault", {
274 274 {
275 275 "TIME UUID SUNW-MSG-ID "
276 276 "EVENT",
277 277 (fmd_log_rec_f *)flt_short
278 278 }, {
279 279 "TIME UUID SUNW-MSG-ID "
280 280 "EVENT",
281 281 (fmd_log_rec_f *)flt_verb1
282 282 }, {
283 283 "TIME UUID"
284 284 " SUNW-MSG-ID",
285 285 (fmd_log_rec_f *)flt_verb2
286 286 }, {
287 287 "TIME UUID"
288 288 " SUNW-MSG-ID",
289 289 (fmd_log_rec_f *)flt_pretty
290 290 }, {
291 291 NULL,
292 292 (fmd_log_rec_f *)flt_msg
293 293 }, {
294 294 NULL,
295 295 (fmd_log_rec_f *)fmdump_print_json
296 296 } }
297 297 };
↓ open down ↓ |
101 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX