xref: /titanic_52/usr/src/lib/fm/libfmnotify/common/libfmnotify.h (revision f6e214c7418f43af38bd8c3a557e3d0a1d311cfa)
1*f6e214c7SGavin Maltby /*
2*f6e214c7SGavin Maltby  * CDDL HEADER START
3*f6e214c7SGavin Maltby  *
4*f6e214c7SGavin Maltby  * The contents of this file are subject to the terms of the
5*f6e214c7SGavin Maltby  * Common Development and Distribution License (the "License").
6*f6e214c7SGavin Maltby  * You may not use this file except in compliance with the License.
7*f6e214c7SGavin Maltby  *
8*f6e214c7SGavin Maltby  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*f6e214c7SGavin Maltby  * or http://www.opensolaris.org/os/licensing.
10*f6e214c7SGavin Maltby  * See the License for the specific language governing permissions
11*f6e214c7SGavin Maltby  * and limitations under the License.
12*f6e214c7SGavin Maltby  *
13*f6e214c7SGavin Maltby  * When distributing Covered Code, include this CDDL HEADER in each
14*f6e214c7SGavin Maltby  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*f6e214c7SGavin Maltby  * If applicable, add the following below this CDDL HEADER, with the
16*f6e214c7SGavin Maltby  * fields enclosed by brackets "[]" replaced with your own identifying
17*f6e214c7SGavin Maltby  * information: Portions Copyright [yyyy] [name of copyright owner]
18*f6e214c7SGavin Maltby  *
19*f6e214c7SGavin Maltby  * CDDL HEADER END
20*f6e214c7SGavin Maltby  */
21*f6e214c7SGavin Maltby 
22*f6e214c7SGavin Maltby /*
23*f6e214c7SGavin Maltby  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24*f6e214c7SGavin Maltby  */
25*f6e214c7SGavin Maltby #ifndef _LIBFMNOTIFY_H
26*f6e214c7SGavin Maltby #define	_LIBFMNOTIFY_H
27*f6e214c7SGavin Maltby 
28*f6e214c7SGavin Maltby #include <stdio.h>
29*f6e214c7SGavin Maltby #include <stdlib.h>
30*f6e214c7SGavin Maltby #include <string.h>
31*f6e214c7SGavin Maltby #include <alloca.h>
32*f6e214c7SGavin Maltby #include <errno.h>
33*f6e214c7SGavin Maltby #include <libscf.h>
34*f6e214c7SGavin Maltby #include <limits.h>
35*f6e214c7SGavin Maltby #include <strings.h>
36*f6e214c7SGavin Maltby #include <sys/corectl.h>
37*f6e214c7SGavin Maltby #include <sys/resource.h>
38*f6e214c7SGavin Maltby #include <sys/types.h>
39*f6e214c7SGavin Maltby #include <unistd.h>
40*f6e214c7SGavin Maltby #include <fm/diagcode.h>
41*f6e214c7SGavin Maltby #include <fm/fmd_msg.h>
42*f6e214c7SGavin Maltby #include <fm/libfmevent.h>
43*f6e214c7SGavin Maltby 
44*f6e214c7SGavin Maltby #ifdef __cplusplus
45*f6e214c7SGavin Maltby extern "C" {
46*f6e214c7SGavin Maltby #endif
47*f6e214c7SGavin Maltby 
48*f6e214c7SGavin Maltby #define	ND_DICTDIR "usr/lib/fm/dict"
49*f6e214c7SGavin Maltby #define	ND_UNKNOWN "UNKNOWN"
50*f6e214c7SGavin Maltby 
51*f6e214c7SGavin Maltby typedef struct nd_hdl {
52*f6e214c7SGavin Maltby 	boolean_t	nh_debug;
53*f6e214c7SGavin Maltby 	boolean_t	nh_is_daemon;
54*f6e214c7SGavin Maltby 	boolean_t	nh_keep_running;
55*f6e214c7SGavin Maltby 	/* handle for libfmevent calls */
56*f6e214c7SGavin Maltby 	fmev_shdl_t	nh_evhdl;
57*f6e214c7SGavin Maltby 	/* handle for libfmd_msg calls */
58*f6e214c7SGavin Maltby 	fmd_msg_hdl_t	*nh_msghdl;
59*f6e214c7SGavin Maltby 	FILE		*nh_log_fd;
60*f6e214c7SGavin Maltby 	char		*nh_rootdir;
61*f6e214c7SGavin Maltby 	const char	*nh_pname;
62*f6e214c7SGavin Maltby } nd_hdl_t;
63*f6e214c7SGavin Maltby 
64*f6e214c7SGavin Maltby const char FMNOTIFY_MSG_DOMAIN[] = "FMNOTIFY";
65*f6e214c7SGavin Maltby 
66*f6e214c7SGavin Maltby typedef struct nd_ev_info {
67*f6e214c7SGavin Maltby 	fmev_t ei_ev;
68*f6e214c7SGavin Maltby 	const char *ei_class;
69*f6e214c7SGavin Maltby 	char *ei_descr;
70*f6e214c7SGavin Maltby 	char *ei_severity;
71*f6e214c7SGavin Maltby 	char *ei_diagcode;
72*f6e214c7SGavin Maltby 	char *ei_url;
73*f6e214c7SGavin Maltby 	char *ei_uuid;
74*f6e214c7SGavin Maltby 	char *ei_fmri;
75*f6e214c7SGavin Maltby 	char *ei_from_state;
76*f6e214c7SGavin Maltby 	char *ei_to_state;
77*f6e214c7SGavin Maltby 	char *ei_reason;
78*f6e214c7SGavin Maltby 	nvlist_t *ei_payload;
79*f6e214c7SGavin Maltby } nd_ev_info_t;
80*f6e214c7SGavin Maltby 
81*f6e214c7SGavin Maltby 
82*f6e214c7SGavin Maltby void nd_cleanup(nd_hdl_t *);
83*f6e214c7SGavin Maltby void nd_dump_nvlist(nd_hdl_t *, nvlist_t *);
84*f6e214c7SGavin Maltby void nd_debug(nd_hdl_t *, const char *, ...);
85*f6e214c7SGavin Maltby void nd_error(nd_hdl_t *, const char *, ...);
86*f6e214c7SGavin Maltby void nd_abort(nd_hdl_t *, const char *, ...);
87*f6e214c7SGavin Maltby void nd_daemonize(nd_hdl_t *);
88*f6e214c7SGavin Maltby int nd_get_boolean_prop(nd_hdl_t *, const char *, const char *, const char *,
89*f6e214c7SGavin Maltby     uint8_t *);
90*f6e214c7SGavin Maltby int nd_get_astring_prop(nd_hdl_t *, const char *, const char *, const char *,
91*f6e214c7SGavin Maltby     char **);
92*f6e214c7SGavin Maltby char *nd_get_event_fmri(nd_hdl_t *, fmev_t);
93*f6e214c7SGavin Maltby int nd_get_event_info(nd_hdl_t *, const char *, fmev_t, nd_ev_info_t **);
94*f6e214c7SGavin Maltby int nd_get_notify_prefs(nd_hdl_t *, const char *, fmev_t, nvlist_t ***,
95*f6e214c7SGavin Maltby     uint_t *);
96*f6e214c7SGavin Maltby int nd_split_list(nd_hdl_t *, char *, char *, char ***, uint_t *);
97*f6e214c7SGavin Maltby int nd_join_strarray(nd_hdl_t *, char **, uint_t, char **);
98*f6e214c7SGavin Maltby int nd_merge_strarray(nd_hdl_t *, char **, uint_t, char **, uint_t, char ***);
99*f6e214c7SGavin Maltby void nd_free_event_info(nd_ev_info_t *);
100*f6e214c7SGavin Maltby void nd_free_nvlarray(nvlist_t **, uint_t);
101*f6e214c7SGavin Maltby void nd_free_strarray(char **, uint_t);
102*f6e214c7SGavin Maltby int nd_get_diagcode(nd_hdl_t *, const char *, const char *, char *, size_t);
103*f6e214c7SGavin Maltby 
104*f6e214c7SGavin Maltby 
105*f6e214c7SGavin Maltby #ifdef	__cplusplus
106*f6e214c7SGavin Maltby }
107*f6e214c7SGavin Maltby #endif
108*f6e214c7SGavin Maltby 
109*f6e214c7SGavin Maltby #endif	/* _LIBFMNOTIFY_H */
110