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 /*
23  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #include <string.h>
27 #include "fmevt.h"
28 
29 /*
30  * Support for the FMEV_RULESET_ON_SUNOS ruleset.
31  */
32 
33 /*
34  * Panic events.
35  */
36 
37 /*ARGSUSED*/
38 static int
pp_sunos_panic(char * classes[FMEVT_FANOUT_MAX],nvlist_t * attr[FMEVT_FANOUT_MAX],const char * ruleset,const nvlist_t * detector,nvlist_t * rawattr,const struct fmevt_ppargs * eap)39 pp_sunos_panic(char *classes[FMEVT_FANOUT_MAX],
40     nvlist_t *attr[FMEVT_FANOUT_MAX], const char *ruleset,
41     const nvlist_t *detector, nvlist_t *rawattr,
42     const struct fmevt_ppargs *eap)
43 
44 {
45 	nvlist_t *myattr;
46 	time_t panictime32;
47 	int64_t panictime;
48 	char buf[128];
49 	struct tm ts;
50 
51 	if (strcmp(eap->pp_rawsubclass, "dump_pending_on_device") != 0 &&
52 	    strcmp(eap->pp_rawsubclass, "savecore_failure") != 0 &&
53 	    strcmp(eap->pp_rawsubclass, "dump_available") != 0)
54 		return (0);
55 
56 	if (snprintf(classes[0], FMEVT_MAX_CLASS, "%s.%s.%s", FM_IREPORT_CLASS,
57 	    "os.sunos.panic", eap->pp_rawsubclass) >= FMEVT_MAX_CLASS - 1)
58 		return (0);
59 
60 	if (nvlist_lookup_int64(rawattr, "crashtime", &panictime) != 0)
61 		return (0);
62 
63 	panictime32 = (time_t)panictime;
64 
65 	myattr = fmd_nvl_dup(fmevt_hdl, rawattr, FMD_SLEEP);
66 
67 	if (localtime_r(&panictime32, &ts) != NULL &&
68 	    strftime(buf, sizeof (buf), "%c %Z", &ts) != 0)
69 		(void) nvlist_add_string(myattr, "panic-time", buf);
70 
71 	attr[0] = myattr;
72 	return (1);
73 }
74 
75 
76 /*ARGSUSED*/
77 uint_t
fmevt_pp_on_sunos(char * classes[FMEVT_FANOUT_MAX],nvlist_t * attr[FMEVT_FANOUT_MAX],const char * ruleset,const nvlist_t * detector,nvlist_t * rawattr,const struct fmevt_ppargs * eap)78 fmevt_pp_on_sunos(char *classes[FMEVT_FANOUT_MAX],
79     nvlist_t *attr[FMEVT_FANOUT_MAX], const char *ruleset,
80     const nvlist_t *detector, nvlist_t *rawattr,
81     const struct fmevt_ppargs *eap)
82 {
83 	if (strcmp(eap->pp_rawclass, "panic") == 0)
84 		return (pp_sunos_panic(classes, attr, ruleset,
85 		    detector, rawattr, eap));
86 
87 	return (0);
88 }
89