10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 53323Scindi * Common Development and Distribution License (the "License"). 63323Scindi * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*9501SRobert.Johnston@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #include <fmdump.h> 270Sstevel@tonic-gate #include <stdio.h> 283323Scindi #include <strings.h> 290Sstevel@tonic-gate 300Sstevel@tonic-gate /*ARGSUSED*/ 310Sstevel@tonic-gate static int 320Sstevel@tonic-gate flt_short(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp) 330Sstevel@tonic-gate { 346276Scy152378 char buf[32], str[32]; 356276Scy152378 char *class = NULL, *uuid = "-", *code = "-"; 360Sstevel@tonic-gate 370Sstevel@tonic-gate (void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_UUID, &uuid); 380Sstevel@tonic-gate (void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_DIAG_CODE, &code); 390Sstevel@tonic-gate 406276Scy152378 (void) nvlist_lookup_string(rp->rec_nvl, FM_CLASS, &class); 416276Scy152378 if (class != NULL && strcmp(class, FM_LIST_REPAIRED_CLASS) == 0) { 426276Scy152378 (void) snprintf(str, sizeof (str), "%s %s", code, "Repaired"); 436276Scy152378 code = str; 446276Scy152378 } 457275Sstephh if (class != NULL && strcmp(class, FM_LIST_RESOLVED_CLASS) == 0) { 467275Sstephh (void) snprintf(str, sizeof (str), "%s %s", code, "Resolved"); 477275Sstephh code = str; 487275Sstephh } 497275Sstephh 507275Sstephh if (class != NULL && strcmp(class, FM_LIST_UPDATED_CLASS) == 0) { 517275Sstephh (void) snprintf(str, sizeof (str), "%s %s", code, "Updated"); 527275Sstephh code = str; 537275Sstephh } 546276Scy152378 555609Scy152378 fmdump_printf(fp, "%-20s %-32s %s\n", 565609Scy152378 fmdump_date(buf, sizeof (buf), rp), uuid, code); 570Sstevel@tonic-gate 580Sstevel@tonic-gate return (0); 590Sstevel@tonic-gate } 600Sstevel@tonic-gate 610Sstevel@tonic-gate static int 620Sstevel@tonic-gate flt_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp) 630Sstevel@tonic-gate { 640Sstevel@tonic-gate uint_t i, size = 0; 650Sstevel@tonic-gate nvlist_t **nva; 667275Sstephh uint8_t *ba; 670Sstevel@tonic-gate 680Sstevel@tonic-gate (void) flt_short(lp, rp, fp); 690Sstevel@tonic-gate (void) nvlist_lookup_uint32(rp->rec_nvl, FM_SUSPECT_FAULT_SZ, &size); 700Sstevel@tonic-gate 710Sstevel@tonic-gate if (size != 0) { 720Sstevel@tonic-gate (void) nvlist_lookup_nvlist_array(rp->rec_nvl, 730Sstevel@tonic-gate FM_SUSPECT_FAULT_LIST, &nva, &size); 747275Sstephh (void) nvlist_lookup_uint8_array(rp->rec_nvl, 757275Sstephh FM_SUSPECT_FAULT_STATUS, &ba, &size); 760Sstevel@tonic-gate } 770Sstevel@tonic-gate 780Sstevel@tonic-gate for (i = 0; i < size; i++) { 791414Scindi char *class = NULL, *rname = NULL, *aname = NULL, *fname = NULL; 803323Scindi char *loc = NULL; 811414Scindi nvlist_t *fru, *asru, *rsrc; 820Sstevel@tonic-gate uint8_t pct = 0; 830Sstevel@tonic-gate 840Sstevel@tonic-gate (void) nvlist_lookup_uint8(nva[i], FM_FAULT_CERTAINTY, &pct); 850Sstevel@tonic-gate (void) nvlist_lookup_string(nva[i], FM_CLASS, &class); 860Sstevel@tonic-gate 870Sstevel@tonic-gate if (nvlist_lookup_nvlist(nva[i], FM_FAULT_FRU, &fru) == 0) 880Sstevel@tonic-gate fname = fmdump_nvl2str(fru); 890Sstevel@tonic-gate 901414Scindi if (nvlist_lookup_nvlist(nva[i], FM_FAULT_ASRU, &asru) == 0) 911414Scindi aname = fmdump_nvl2str(asru); 921414Scindi 931414Scindi if (nvlist_lookup_nvlist(nva[i], FM_FAULT_RESOURCE, &rsrc) == 0) 941414Scindi rname = fmdump_nvl2str(rsrc); 951414Scindi 963323Scindi if (nvlist_lookup_string(nva[i], FM_FAULT_LOCATION, &loc) 973323Scindi == 0) { 983530Srb144127 if (fname && strncmp(fname, FM_FMRI_LEGACY_HC_PREFIX, 993323Scindi sizeof (FM_FMRI_LEGACY_HC_PREFIX)) == 0) 1003323Scindi loc = fname + sizeof (FM_FMRI_LEGACY_HC_PREFIX); 1013323Scindi } 1023323Scindi 1033323Scindi 1047275Sstephh fmdump_printf(fp, " %3u%% %s", 1051414Scindi pct, class ? class : "-"); 1060Sstevel@tonic-gate 1077275Sstephh if (ba[i] & FM_SUSPECT_FAULTY) 1087275Sstephh fmdump_printf(fp, "\n\n"); 1097275Sstephh else if (ba[i] & FM_SUSPECT_NOT_PRESENT) 1107275Sstephh fmdump_printf(fp, "\tRemoved\n\n"); 1117275Sstephh else if (ba[i] & FM_SUSPECT_REPLACED) 1127275Sstephh fmdump_printf(fp, "\tReplaced\n\n"); 1137275Sstephh else if (ba[i] & FM_SUSPECT_REPAIRED) 1147275Sstephh fmdump_printf(fp, "\tRepair Attempted\n\n"); 1157275Sstephh else if (ba[i] & FM_SUSPECT_ACQUITTED) 1167275Sstephh fmdump_printf(fp, "\tAcquitted\n\n"); 1177275Sstephh else 1187275Sstephh fmdump_printf(fp, "\n\n"); 1197275Sstephh 1201414Scindi fmdump_printf(fp, " Problem in: %s\n", 1217275Sstephh rname ? rname : "-"); 1221414Scindi 1231414Scindi fmdump_printf(fp, " Affects: %s\n", 1241414Scindi aname ? aname : "-"); 1251414Scindi 1263323Scindi fmdump_printf(fp, " FRU: %s\n", 1271414Scindi fname ? fname : "-"); 1280Sstevel@tonic-gate 1293323Scindi fmdump_printf(fp, " Location: %s\n\n", 1303323Scindi loc ? loc : "-"); 1313323Scindi 1320Sstevel@tonic-gate free(fname); 1331414Scindi free(aname); 1340Sstevel@tonic-gate free(rname); 1350Sstevel@tonic-gate } 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate return (0); 1380Sstevel@tonic-gate } 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate static int 1410Sstevel@tonic-gate flt_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp) 1420Sstevel@tonic-gate { 1430Sstevel@tonic-gate const struct fmdump_fmt *efp = &fmdump_err_ops.do_formats[FMDUMP_VERB1]; 1440Sstevel@tonic-gate const struct fmdump_fmt *ffp = &fmdump_flt_ops.do_formats[FMDUMP_VERB1]; 1450Sstevel@tonic-gate uint_t i; 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate fmdump_printf(fp, "%s\n", ffp->do_hdr); 1480Sstevel@tonic-gate (void) flt_short(lp, rp, fp); 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate if (rp->rec_nrefs != 0) 1510Sstevel@tonic-gate fmdump_printf(fp, "\n %s\n", efp->do_hdr); 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate for (i = 0; i < rp->rec_nrefs; i++) { 1540Sstevel@tonic-gate fmdump_printf(fp, " "); 1550Sstevel@tonic-gate efp->do_func(lp, &rp->rec_xrefs[i], fp); 1560Sstevel@tonic-gate } 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate fmdump_printf(fp, "\n"); 1590Sstevel@tonic-gate nvlist_print(fp, rp->rec_nvl); 1600Sstevel@tonic-gate fmdump_printf(fp, "\n"); 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate return (0); 1630Sstevel@tonic-gate } 1640Sstevel@tonic-gate 165*9501SRobert.Johnston@Sun.COM /* 166*9501SRobert.Johnston@Sun.COM * There is a lack of uniformity in how the various entries in our diagnosis 167*9501SRobert.Johnston@Sun.COM * are terminated. Some end with one newline, others with two. This makes the 168*9501SRobert.Johnston@Sun.COM * output of fmdump -m look a bit ugly. Therefore we postprocess the message 169*9501SRobert.Johnston@Sun.COM * before printing it, removing consecutive occurences of newlines. 170*9501SRobert.Johnston@Sun.COM */ 171*9501SRobert.Johnston@Sun.COM static void 172*9501SRobert.Johnston@Sun.COM postprocess_msg(char *msg) 173*9501SRobert.Johnston@Sun.COM { 174*9501SRobert.Johnston@Sun.COM int i = 0, j = 0; 175*9501SRobert.Johnston@Sun.COM char *buf; 176*9501SRobert.Johnston@Sun.COM 177*9501SRobert.Johnston@Sun.COM if ((buf = malloc(strlen(msg) + 1)) == NULL) 178*9501SRobert.Johnston@Sun.COM return; 179*9501SRobert.Johnston@Sun.COM 180*9501SRobert.Johnston@Sun.COM buf[j++] = msg[i++]; 181*9501SRobert.Johnston@Sun.COM for (i = 1; i < strlen(msg); i++) { 182*9501SRobert.Johnston@Sun.COM if (!(msg[i] == '\n' && msg[i - 1] == '\n')) 183*9501SRobert.Johnston@Sun.COM buf[j++] = msg[i]; 184*9501SRobert.Johnston@Sun.COM } 185*9501SRobert.Johnston@Sun.COM buf[j] = '\0'; 186*9501SRobert.Johnston@Sun.COM (void) strncpy(msg, buf, j+1); 187*9501SRobert.Johnston@Sun.COM free(buf); 188*9501SRobert.Johnston@Sun.COM } 189*9501SRobert.Johnston@Sun.COM 190*9501SRobert.Johnston@Sun.COM /*ARGSUSED*/ 191*9501SRobert.Johnston@Sun.COM static int 192*9501SRobert.Johnston@Sun.COM flt_msg(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp) 193*9501SRobert.Johnston@Sun.COM { 194*9501SRobert.Johnston@Sun.COM char *msg; 195*9501SRobert.Johnston@Sun.COM 196*9501SRobert.Johnston@Sun.COM if ((msg = fmd_msg_gettext_nv(g_msg, NULL, rp->rec_nvl)) == NULL) { 197*9501SRobert.Johnston@Sun.COM (void) fprintf(stderr, "%s: failed to format message: %s\n", 198*9501SRobert.Johnston@Sun.COM g_pname, strerror(errno)); 199*9501SRobert.Johnston@Sun.COM g_errs++; 200*9501SRobert.Johnston@Sun.COM return (-1); 201*9501SRobert.Johnston@Sun.COM } else { 202*9501SRobert.Johnston@Sun.COM postprocess_msg(msg); 203*9501SRobert.Johnston@Sun.COM fmdump_printf(fp, "%s\n", msg); 204*9501SRobert.Johnston@Sun.COM free(msg); 205*9501SRobert.Johnston@Sun.COM } 206*9501SRobert.Johnston@Sun.COM 207*9501SRobert.Johnston@Sun.COM return (0); 208*9501SRobert.Johnston@Sun.COM } 209*9501SRobert.Johnston@Sun.COM 2100Sstevel@tonic-gate const fmdump_ops_t fmdump_flt_ops = { 2110Sstevel@tonic-gate "fault", { 2120Sstevel@tonic-gate { 2130Sstevel@tonic-gate "TIME UUID SUNW-MSG-ID", 2140Sstevel@tonic-gate (fmd_log_rec_f *)flt_short 2150Sstevel@tonic-gate }, { 2160Sstevel@tonic-gate "TIME UUID SUNW-MSG-ID", 2170Sstevel@tonic-gate (fmd_log_rec_f *)flt_verb1 2180Sstevel@tonic-gate }, { 2190Sstevel@tonic-gate NULL, 2200Sstevel@tonic-gate (fmd_log_rec_f *)flt_verb2 221*9501SRobert.Johnston@Sun.COM }, { 222*9501SRobert.Johnston@Sun.COM NULL, 223*9501SRobert.Johnston@Sun.COM (fmd_log_rec_f *)flt_msg 2240Sstevel@tonic-gate } } 2250Sstevel@tonic-gate }; 226