/* * dlopen() the platform filter library and dlsym() the filter funcs. */ static void exs_filter_init(fmd_hdl_t *hdl) { char *propstr = fmd_prop_get_string(hdl, "filter_path"); if (propstr == NULL) { fmd_hdl_debug(hdl, "No filter plugin specified"); Send_filter = NULL; Post_filter = NULL; return; } else { if ((Dlp = dlopen(propstr, RTLD_LOCAL | RTLD_NOW)) == NULL) { fmd_hdl_debug(hdl, "Failed to dlopen filter plugin"); Send_filter = NULL; Post_filter = NULL; fmd_prop_free_string(hdl, propstr); return; } if ((Send_filter = (int (*)())dlsym(Dlp, "send_filter")) == NULL) { fmd_hdl_debug(hdl, "failed to dlsym send_filter()"); Send_filter = NULL; } if ((Post_filter = (int (*)())dlsym(Dlp, "post_filter")) == NULL) { fmd_hdl_debug(hdl, "failed to dlsym post_filter()"); Post_filter = NULL; } } fmd_prop_free_string(hdl, propstr); }
int etm_xport_init(fmd_hdl_t *hdl) { _etm_xport_addr_t **_addrv; /* address vector */ int i; /* vector index */ ssize_t n; /* gen use */ int rv; /* ret val */ struct stat stat_buf; /* file stat struct */ char *fn; /* filename of dev node */ rv = 0; /* assume good */ _addrv = NULL; if (hdl == NULL) { rv = (-EINVAL); goto func_ret; } fmd_hdl_debug(hdl, "info: xport initializing\n"); /* setup statistics and properties from FMD */ (void) fmd_stat_create(hdl, FMD_STAT_NOALLOC, sizeof (etm_xport_stats) / sizeof (fmd_stat_t), (fmd_stat_t *)&etm_xport_stats); etm_xport_debug_lvl = fmd_prop_get_int32(hdl, ETM_PROP_NM_DEBUG_LVL); etm_xport_addrs = fmd_prop_get_string(hdl, ETM_PROP_NM_XPORT_ADDRS); fmd_hdl_debug(hdl, "info: etm_xport_debug_lvl %d\n", etm_xport_debug_lvl); fmd_hdl_debug(hdl, "info: etm_xport_addrs %s\n", etm_xport_addrs); /* decide whether to fake [some of] the device driver behavior */ etm_xport_should_fake_dd = 0; /* default to false */ fn = etm_xport_get_fn(hdl, ETM_IO_OP_RD); if (stat(fn, &stat_buf) < 0) { /* errno assumed set by above call */ fmd_hdl_error(hdl, "error: bad device node %s errno %d\n", fn, errno); rv = (-errno); goto func_ret; } if (!S_ISCHR(stat_buf.st_mode) && use_vldc == 0) { etm_xport_should_fake_dd = 1; /* not a char driver */ } fmd_hdl_debug(hdl, "info: etm_xport_should_fake_dd %d\n", etm_xport_should_fake_dd); /* validate each default dst transport address */ if ((_addrv = (void *)etm_xport_get_ev_addrv(hdl, NULL)) == NULL) { /* errno assumed set by above call */ rv = (-errno); goto func_ret; } for (i = 0; _addrv[i] != NULL; i++) { if ((n = etm_xport_valid_addr(_addrv[i])) < 0) { fmd_hdl_error(hdl, "error: bad xport addr %p\n", _addrv[i]); rv = n; goto func_ret; } } /* foreach dst addr */ if (use_vldc) { etm_xport_vldc_conn = etm_xport_open(hdl, _addrv[0]); if (etm_xport_vldc_conn == NULL) { fmd_hdl_debug(hdl, "info: etm_xport_open() failed\n"); } } func_ret: if (_addrv != NULL) { etm_xport_free_addrv(hdl, (void *)_addrv); } if (rv >= 0) { fmd_hdl_debug(hdl, "info: xport initialized ok\n"); } return (rv); } /* etm_xport_init() */
static char * etm_xport_get_fn(fmd_hdl_t *hdl, int io_op) { static char fn_wr[PATH_MAX] = {0}; /* fn for write */ static char fn_rd[PATH_MAX] = {0}; /* fn for read/peek */ char *rv; /* ret val */ char *prop_str; /* property string */ char *cp; /* char ptr */ rv = NULL; /* use cached copies if avail */ if ((io_op == ETM_IO_OP_WR) && (fn_wr[0] != '\0')) { return (fn_wr); } if (((io_op == ETM_IO_OP_RD) || (io_op == ETM_IO_OP_PK)) && (fn_rd[0] != '\0')) { return (fn_rd); } /* create cached copies if empty "" property string */ prop_str = fmd_prop_get_string(hdl, ETM_PROP_NM_XPORT_ADDRS); if (etm_xport_debug_lvl >= 2) { fmd_hdl_debug(hdl, "info: etm_xport_get_fn prop_str %s\n", prop_str); } if (strlen(prop_str) == 0) { struct stat buf; char *fname; if (stat(ETM_XPORT_DEV_VLDC, &buf) == 0) { use_vldc = 1; fname = ETM_XPORT_DEV_VLDC; } else { use_vldc = 0; fname = ETM_XPORT_DEV_FN_SP; } (void) strncpy(fn_wr, fname, PATH_MAX - 1); (void) strncpy(fn_rd, fname, PATH_MAX - 1); rv = fn_rd; if (io_op == ETM_IO_OP_WR) { rv = fn_wr; } goto func_ret; } /* if no/empty property set */ /* create cached copies if "write[|read]" property string */ if (io_op == ETM_IO_OP_WR) { (void) strncpy(fn_wr, prop_str, PATH_MAX - 1); if ((cp = strchr(fn_wr, '|')) != NULL) { *cp = '\0'; } rv = fn_wr; } else { if ((cp = strchr(prop_str, '|')) != NULL) { cp++; } else { cp = prop_str; } (void) strncpy(fn_rd, cp, PATH_MAX - 1); rv = fn_rd; } /* whether io op is write/read/peek */ func_ret: if (etm_xport_debug_lvl >= 2) { fmd_hdl_debug(hdl, "info: etm_xport_get_fn fn_wr %s fn_rd %s\n", fn_wr, fn_rd); } fmd_prop_free_string(hdl, prop_str); return (rv); } /* etm_xport_get_fn() */