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