xref: /titanic_50/usr/src/cmd/fm/fmdump/common/error.c (revision b494511a9cf72b1fc4eb13a0e593f55c624ab829)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #include <fmdump.h>
26 #include <stdio.h>
27 #include <time.h>
28 
29 /*ARGSUSED*/
30 static int
31 err_short(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
32 {
33 	char buf[32];
34 
35 	fmdump_printf(fp, "%-20s %-32s\n",
36 	    fmdump_date(buf, sizeof (buf), rp), rp->rec_class);
37 
38 	return (0);
39 }
40 
41 /*ARGSUSED*/
42 static int
43 err_verb1(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
44 {
45 	uint64_t ena = 0;
46 	char buf[32];
47 
48 	(void) nvlist_lookup_uint64(rp->rec_nvl, FM_EREPORT_ENA, &ena);
49 
50 	fmdump_printf(fp, "%-20s %-37s 0x%016llx\n",
51 	    fmdump_date(buf, sizeof (buf), rp), rp->rec_class, ena);
52 
53 	return (0);
54 }
55 
56 /*ARGSUSED*/
57 static int
58 err_verb23_cmn(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp,
59     nvlist_prtctl_t pctl)
60 {
61 	char buf[32];
62 
63 	fmdump_printf(fp, "%-20s.%9.9llu %s\n",
64 	    fmdump_year(buf, sizeof (buf), rp), rp->rec_nsec, rp->rec_class);
65 
66 	if (pctl)
67 		nvlist_prt(rp->rec_nvl, pctl);
68 	else
69 		nvlist_print(fp, rp->rec_nvl);
70 
71 	fmdump_printf(fp, "\n");
72 	return (0);
73 }
74 
75 static int
76 err_verb2(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
77 {
78 	return (err_verb23_cmn(lp, rp, fp, NULL));
79 }
80 
81 static int
82 err_pretty(fmd_log_t *lp, const fmd_log_record_t *rp, FILE *fp)
83 {
84 	nvlist_prtctl_t pctl;
85 	int rc;
86 
87 	if ((pctl = nvlist_prtctl_alloc()) != NULL) {
88 		nvlist_prtctl_setdest(pctl, fp);
89 		nvlist_prtctlop_nvlist(pctl, fmdump_render_nvlist, NULL);
90 	}
91 
92 	rc = err_verb23_cmn(lp, rp, fp, pctl);
93 
94 	nvlist_prtctl_free(pctl);
95 	return (rc);
96 }
97 
98 const fmdump_ops_t fmdump_err_ops = {
99 "error", {
100 {
101 "TIME                 CLASS",
102 (fmd_log_rec_f *)err_short
103 }, {
104 "TIME                 CLASS                                 ENA",
105 (fmd_log_rec_f *)err_verb1
106 }, {
107 "TIME                           CLASS",
108 (fmd_log_rec_f *)err_verb2
109 }, {
110 "TIME                           CLASS",
111 (fmd_log_rec_f *)err_pretty
112 }, {
113 NULL, NULL
114 } }
115 };
116