xref: /titanic_44/usr/src/lib/fm/libfmnotify/common/libfmnotify.h (revision db8b037b5616a366b7dfdc01ef9552f02f9adfdd)
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 #ifndef _LIBFMNOTIFY_H
26 #define	_LIBFMNOTIFY_H
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <alloca.h>
32 #include <errno.h>
33 #include <libscf.h>
34 #include <limits.h>
35 #include <strings.h>
36 #include <sys/corectl.h>
37 #include <sys/resource.h>
38 #include <sys/types.h>
39 #include <unistd.h>
40 #include <fm/diagcode.h>
41 #include <fm/fmd_msg.h>
42 #include <fm/libfmevent.h>
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 #define	ND_DICTDIR "usr/lib/fm/dict"
49 #define	ND_UNKNOWN "UNKNOWN"
50 
51 typedef struct nd_hdl {
52 	boolean_t	nh_debug;
53 	boolean_t	nh_is_daemon;
54 	boolean_t	nh_keep_running;
55 	/* handle for libfmevent calls */
56 	fmev_shdl_t	nh_evhdl;
57 	/* handle for libfmd_msg calls */
58 	fmd_msg_hdl_t	*nh_msghdl;
59 	FILE		*nh_log_fd;
60 	char		*nh_rootdir;
61 	const char	*nh_pname;
62 } nd_hdl_t;
63 
64 const char FMNOTIFY_MSG_DOMAIN[] = "FMNOTIFY";
65 
66 typedef struct nd_ev_info {
67 	fmev_t ei_ev;
68 	const char *ei_class;
69 	char *ei_descr;
70 	char *ei_severity;
71 	char *ei_diagcode;
72 	char *ei_url;
73 	char *ei_uuid;
74 	char *ei_fmri;
75 	char *ei_from_state;
76 	char *ei_to_state;
77 	char *ei_reason;
78 	nvlist_t *ei_payload;
79 } nd_ev_info_t;
80 
81 
82 void nd_cleanup(nd_hdl_t *);
83 void nd_dump_nvlist(nd_hdl_t *, nvlist_t *);
84 void nd_debug(nd_hdl_t *, const char *, ...);
85 void nd_error(nd_hdl_t *, const char *, ...);
86 void nd_abort(nd_hdl_t *, const char *, ...);
87 void nd_daemonize(nd_hdl_t *);
88 int nd_get_boolean_prop(nd_hdl_t *, const char *, const char *, const char *,
89     uint8_t *);
90 int nd_get_astring_prop(nd_hdl_t *, const char *, const char *, const char *,
91     char **);
92 char *nd_get_event_fmri(nd_hdl_t *, fmev_t);
93 int nd_get_event_info(nd_hdl_t *, const char *, fmev_t, nd_ev_info_t **);
94 int nd_get_notify_prefs(nd_hdl_t *, const char *, fmev_t, nvlist_t ***,
95     uint_t *);
96 int nd_split_list(nd_hdl_t *, char *, char *, char ***, uint_t *);
97 int nd_join_strarray(nd_hdl_t *, char **, uint_t, char **);
98 int nd_merge_strarray(nd_hdl_t *, char **, uint_t, char **, uint_t, char ***);
99 void nd_free_event_info(nd_ev_info_t *);
100 void nd_free_nvlarray(nvlist_t **, uint_t);
101 void nd_free_strarray(char **, uint_t);
102 int nd_get_diagcode(nd_hdl_t *, const char *, const char *, char *, size_t);
103 
104 
105 #ifdef	__cplusplus
106 }
107 #endif
108 
109 #endif	/* _LIBFMNOTIFY_H */
110