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 /* 229501SRobert.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]; 144*10928SStephen.Hanson@Sun.COM const struct fmdump_fmt *ffp = &fmdump_flt_ops.do_formats[FMDUMP_VERB2]; 1450Sstevel@tonic-gate uint_t i; 146*10928SStephen.Hanson@Sun.COM char buf[32], str[32]; 147*10928SStephen.Hanson@Sun.COM char *class = NULL, *uuid = "-", *code = "-"; 148*10928SStephen.Hanson@Sun.COM 149*10928SStephen.Hanson@Sun.COM (void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_UUID, &uuid); 150*10928SStephen.Hanson@Sun.COM (void) nvlist_lookup_string(rp->rec_nvl, FM_SUSPECT_DIAG_CODE, &code); 151*10928SStephen.Hanson@Sun.COM 152*10928SStephen.Hanson@Sun.COM (void) nvlist_lookup_string(rp->rec_nvl, FM_CLASS, &class); 153*10928SStephen.Hanson@Sun.COM if (class != NULL && strcmp(class, FM_LIST_REPAIRED_CLASS) == 0) { 154*10928SStephen.Hanson@Sun.COM (void) snprintf(str, sizeof (str), "%s %s", code, "Repaired"); 155*10928SStephen.Hanson@Sun.COM code = str; 156*10928SStephen.Hanson@Sun.COM } 157*10928SStephen.Hanson@Sun.COM if (class != NULL && strcmp(class, FM_LIST_RESOLVED_CLASS) == 0) { 158*10928SStephen.Hanson@Sun.COM (void) snprintf(str, sizeof (str), "%s %s", code, "Resolved"); 159*10928SStephen.Hanson@Sun.COM code = str; 160*10928SStephen.Hanson@Sun.COM } 161*10928SStephen.Hanson@Sun.COM if (class != NULL && strcmp(class, FM_LIST_UPDATED_CLASS) == 0) { 162*10928SStephen.Hanson@Sun.COM (void) snprintf(str, sizeof (str), "%s %s", code, "Updated"); 163*10928SStephen.Hanson@Sun.COM code = str; 164*10928SStephen.Hanson@Sun.COM } 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate fmdump_printf(fp, "%s\n", ffp->do_hdr); 167*10928SStephen.Hanson@Sun.COM fmdump_printf(fp, "%-20s.%9.9llu %-32s %s\n", 168*10928SStephen.Hanson@Sun.COM fmdump_year(buf, sizeof (buf), rp), rp->rec_nsec, uuid, code); 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate if (rp->rec_nrefs != 0) 1710Sstevel@tonic-gate fmdump_printf(fp, "\n %s\n", efp->do_hdr); 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate for (i = 0; i < rp->rec_nrefs; i++) { 1740Sstevel@tonic-gate fmdump_printf(fp, " "); 1750Sstevel@tonic-gate efp->do_func(lp, &rp->rec_xrefs[i], fp); 1760Sstevel@tonic-gate } 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate fmdump_printf(fp, "\n"); 1790Sstevel@tonic-gate nvlist_print(fp, rp->rec_nvl); 1800Sstevel@tonic-gate fmdump_printf(fp, "\n"); 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate return (0); 1830Sstevel@tonic-gate } 1840Sstevel@tonic-gate 1859501SRobert.Johnston@Sun.COM /* 1869501SRobert.Johnston@Sun.COM * There is a lack of uniformity in how the various entries in our diagnosis 1879501SRobert.Johnston@Sun.COM * are terminated. Some end with one newline, others with two. This makes the 1889501SRobert.Johnston@Sun.COM * output of fmdump -m look a bit ugly. Therefore we postprocess the message 1899501SRobert.Johnston@Sun.COM * before printing it, removing consecutive occurences of newlines. 1909501SRobert.Johnston@Sun.COM */ 1919501SRobert.Johnston@Sun.COM static void 1929501SRobert.Johnston@Sun.COM postprocess_msg(char *msg) 1939501SRobert.Johnston@Sun.COM { 1949501SRobert.Johnston@Sun.COM int i = 0, j = 0; 1959501SRobert.Johnston@Sun.COM char *buf; 1969501SRobert.Johnston@Sun.COM 1979501SRobert.Johnston@Sun.COM if ((buf = malloc(strlen(msg) + 1)) == NULL) 1989501SRobert.Johnston@Sun.COM return; 1999501SRobert.Johnston@Sun.COM 2009501SRobert.Johnston@Sun.COM buf[j++] = msg[i++]; 2019501SRobert.Johnston@Sun.COM for (i = 1; i < strlen(msg); i++) { 2029501SRobert.Johnston@Sun.COM if (!(msg[i] == '\n' && msg[i - 1] == '\n')) 2039501SRobert.Johnston@Sun.COM buf[j++] = msg[i]; 2049501SRobert.Johnston@Sun.COM } 2059501SRobert.Johnston@Sun.COM buf[j] = '\0'; 2069501SRobert.Johnston@Sun.COM (void) strncpy(msg, buf, j+1); 2079501SRobert.Johnston@Sun.COM free(buf); 2089501SRobert.Johnston@Sun.COM } 2099501SRobert.Johnston@Sun.COM 2109501SRobert.Johnston@Sun.COM /*ARGSUSED*/ 2119501SRobert.Johnston@Sun.COM static int 2129501SRobert.Johnston@Sun.COM flt_msg(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp) 2139501SRobert.Johnston@Sun.COM { 2149501SRobert.Johnston@Sun.COM char *msg; 2159501SRobert.Johnston@Sun.COM 2169501SRobert.Johnston@Sun.COM if ((msg = fmd_msg_gettext_nv(g_msg, NULL, rp->rec_nvl)) == NULL) { 2179501SRobert.Johnston@Sun.COM (void) fprintf(stderr, "%s: failed to format message: %s\n", 2189501SRobert.Johnston@Sun.COM g_pname, strerror(errno)); 2199501SRobert.Johnston@Sun.COM g_errs++; 2209501SRobert.Johnston@Sun.COM return (-1); 2219501SRobert.Johnston@Sun.COM } else { 2229501SRobert.Johnston@Sun.COM postprocess_msg(msg); 2239501SRobert.Johnston@Sun.COM fmdump_printf(fp, "%s\n", msg); 2249501SRobert.Johnston@Sun.COM free(msg); 2259501SRobert.Johnston@Sun.COM } 2269501SRobert.Johnston@Sun.COM 2279501SRobert.Johnston@Sun.COM return (0); 2289501SRobert.Johnston@Sun.COM } 2299501SRobert.Johnston@Sun.COM 2300Sstevel@tonic-gate const fmdump_ops_t fmdump_flt_ops = { 2310Sstevel@tonic-gate "fault", { 2320Sstevel@tonic-gate { 2330Sstevel@tonic-gate "TIME UUID SUNW-MSG-ID", 2340Sstevel@tonic-gate (fmd_log_rec_f *)flt_short 2350Sstevel@tonic-gate }, { 2360Sstevel@tonic-gate "TIME UUID SUNW-MSG-ID", 2370Sstevel@tonic-gate (fmd_log_rec_f *)flt_verb1 2380Sstevel@tonic-gate }, { 239*10928SStephen.Hanson@Sun.COM "TIME UUID" 240*10928SStephen.Hanson@Sun.COM " SUNW-MSG-ID", 2410Sstevel@tonic-gate (fmd_log_rec_f *)flt_verb2 2429501SRobert.Johnston@Sun.COM }, { 2439501SRobert.Johnston@Sun.COM NULL, 2449501SRobert.Johnston@Sun.COM (fmd_log_rec_f *)flt_msg 2450Sstevel@tonic-gate } } 2460Sstevel@tonic-gate }; 247