Exemple #1
0
/*
 * 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_fini(fmd_hdl_t *hdl)
{
    fmd_hdl_debug(hdl, "info: xport finalizing\n");

    if (use_vldc && (etm_xport_vldc_conn != NULL)) {
        (void) etm_xport_close(hdl, etm_xport_vldc_conn);
        etm_xport_vldc_conn = NULL;
    }

    /* free any long standing properties from FMD */

    fmd_prop_free_string(hdl, etm_xport_addrs);

    /* cleanup the intermediate read buffer */

    if (etm_xport_irb_tail != etm_xport_irb_head) {
        fmd_hdl_debug(hdl, "warning: xport %d bytes stale data\n",
                      (int)(etm_xport_irb_tail - etm_xport_irb_head));
    }
    fmd_hdl_free(hdl, etm_xport_irb_area, 2 * etm_xport_irb_mtu_sz);
    etm_xport_irb_area = NULL;
    etm_xport_irb_head = NULL;
    etm_xport_irb_tail = NULL;
    etm_xport_irb_mtu_sz = 0;

    /* cleanup statistics from FMD */

    (void) fmd_stat_destroy(hdl,
                            sizeof (etm_xport_stats) / sizeof (fmd_stat_t),
                            (fmd_stat_t *)&etm_xport_stats);

    fmd_hdl_debug(hdl, "info: xport finalized ok\n");
    return (0);

} /* etm_xport_fini() */
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() */