Esempio n. 1
0
static void *
cpumem_alloc(size_t size)
{
    assert(cpumem_hdl != NULL);

    return (fmd_hdl_alloc(cpumem_hdl, size, FMD_SLEEP));
}
Esempio n. 2
0
char *
gmem_mem_serdnm_create(fmd_hdl_t *hdl, const char *serdbase, const char *serial)
{
	const char *fmt = "%s_%s_serd";
	size_t sz = snprintf(NULL, 0, fmt, serdbase, serial) + 1;
	char *nm = fmd_hdl_alloc(hdl, sz, FMD_SLEEP);
	(void) snprintf(nm, sz, fmt, serdbase, serial);

	return (nm);
}
Esempio n. 3
0
static int
get_notify_prefs(fmd_hdl_t *hdl, nvlist_t *ev_nvl, nvlist_t ***pref_nvl,
    uint_t *nprefs)
{
	nvlist_t *top_nvl, **np_nvlarr, *mech_nvl;
	nvlist_t **tmparr;
	int ret, i;
	uint_t nelem, nslelem;

	if ((ret = smf_notify_get_params(&top_nvl, ev_nvl)) != SCF_SUCCESS) {
		ret = scf_error();
		if (ret != SCF_ERROR_NOT_FOUND) {
			fmd_hdl_debug(hdl, "Error looking up notification "
			    "preferences (%s)", scf_strerror(ret));
			return (ret);
		}
		return (ret);
	}

	if (nvlist_lookup_nvlist_array(top_nvl, SCF_NOTIFY_PARAMS, &np_nvlarr,
	    &nelem) != 0) {
		fmd_hdl_debug(hdl, "Malformed preference nvlist\n");
		ret = SCF_ERROR_INVALID_ARGUMENT;
		goto pref_done;
	}

	tmparr = fmd_hdl_alloc(hdl, nelem * sizeof (nvlist_t *), FMD_SLEEP);
	nslelem = 0;

	for (i = 0; i < nelem; i++) {
		if (nvlist_lookup_nvlist(np_nvlarr[i], "syslog", &mech_nvl)
		    == 0)
			tmparr[nslelem++] = fmd_nvl_dup(hdl, mech_nvl,
			    FMD_SLEEP);
	}

	if (nslelem != 0) {
		size_t sz = nslelem * sizeof (nvlist_t *);

		*pref_nvl = fmd_hdl_zalloc(hdl, sz, FMD_SLEEP);
		*nprefs = nslelem;
		bcopy(tmparr, *pref_nvl, sz);
		ret = 0;
	} else {
		*pref_nvl = NULL;
		*nprefs = 0;
		ret = SCF_ERROR_NOT_FOUND;
	}

	fmd_hdl_free(hdl, tmparr, nelem * sizeof (nvlist_t *));
pref_done:
	nvlist_free(top_nvl);
	return (ret);
}
Esempio n. 4
0
char *
gmem_mq_serdnm_create(fmd_hdl_t *hdl, const char *serdbase,
    uint64_t phys_addr, uint16_t cw, uint16_t pos)
{
	const char *fmt = "%s_%llX_%x_%x_serd";
	size_t sz = snprintf(NULL, 0, fmt, serdbase, phys_addr, cw, pos) + 1;
	char *nm = fmd_hdl_alloc(hdl, sz, FMD_SLEEP);
	(void) snprintf(nm, sz, fmt, serdbase, phys_addr, cw, pos);

	return (nm);
}
Esempio n. 5
0
char *
gmem_page_serdnm_create(fmd_hdl_t *hdl, const char *serdbase,
    uint64_t phys_addr)
{
	const char *fmt = "%s_%llXserd";
	size_t sz = snprintf(NULL, 0, fmt, serdbase, phys_addr) + 1;
	char *nm = fmd_hdl_alloc(hdl, sz, FMD_SLEEP);
	(void) snprintf(nm, sz, fmt, serdbase, phys_addr);

	return (nm);
}
Esempio n. 6
0
/*
 * svc.startd generates events using the FMRI shorthand (svc:/foo/bar)
 * instead of the standard form (svc:///foo/bar).  This function converts to
 * the standard representation.  The caller must free the allocated string.
 */
static char *
shortfmri_to_fmristr(fmd_hdl_t *hdl, const char *shortfmristr)
{
	size_t len;
	char *fmristr;

	if (strncmp(shortfmristr, "svc:/", 5) != 0)
		return (NULL);

	len = strlen(shortfmristr) + 3;
	fmristr = fmd_hdl_alloc(hdl, len, FMD_SLEEP);
	(void) snprintf(fmristr, len, "svc:///%s", shortfmristr + 5);

	return (fmristr);
}
Esempio n. 7
0
void *
cmd_buf_read(fmd_hdl_t *hdl, fmd_case_t *cp, const char *bufname, size_t bufsz)
{
	void *buf;
	size_t sz;

	if ((sz = fmd_buf_size(hdl, cp, bufname)) == 0) {
		(void) cmd_set_errno(ENOENT);
		return (NULL);
	} else if (sz != bufsz) {
		(void) cmd_set_errno(EINVAL);
		return (NULL);
	}

	buf = fmd_hdl_alloc(hdl, bufsz, FMD_SLEEP);
	fmd_buf_read(hdl, cp, bufname, buf, bufsz);

	return (buf);
}
Esempio n. 8
0
/*
 * Read back the persistent representation of an active case.
 */
static zfs_case_t *
zfs_case_unserialize(fmd_hdl_t *hdl, fmd_case_t *cp)
{
	zfs_case_t *zcp;
	size_t frulen;

	zcp = fmd_hdl_zalloc(hdl, sizeof (zfs_case_t), FMD_SLEEP);
	zcp->zc_case = cp;

	fmd_buf_read(hdl, cp, CASE_DATA, &zcp->zc_data,
	    sizeof (zcp->zc_data));

	if (zcp->zc_data.zc_version > CASE_DATA_VERSION_SERD) {
		fmd_hdl_free(hdl, zcp, sizeof (zfs_case_t));
		return (NULL);
	}

	if ((frulen = fmd_buf_size(hdl, zcp->zc_case, CASE_FRU)) > 0) {
		zcp->zc_fru = fmd_hdl_alloc(hdl, frulen + 1, FMD_SLEEP);
		fmd_buf_read(hdl, zcp->zc_case, CASE_FRU, zcp->zc_fru,
		    frulen);
		zcp->zc_fru[frulen] = '\0';
	}

	/*
	 * fmd_buf_read() will have already zeroed out the remainder of the
	 * buffer, so we don't have to do anything special if the version
	 * doesn't include the SERD engine name.
	 */

	if (zcp->zc_data.zc_has_remove_timer)
		zcp->zc_remove_timer = fmd_timer_install(hdl, zcp,
		    NULL, zfs_remove_timeout);

	(void) uu_list_insert_before(zfs_cases, NULL, zcp);

	fmd_case_setspecific(hdl, cp, zcp);

	return (zcp);
}
Esempio n. 9
0
/*
 * Take a ruleset specification string and separate it into namespace
 * and subsystem components.
 */
static int
fmevt_rs_burst(fmd_hdl_t *hdl, char *ruleset, char **nsp, char **subsysp,
    boolean_t alloc)
{
	char *ns, *s;
	size_t len;

	if (ruleset == NULL || *ruleset == '\0' ||
	    strnlen(ruleset, FMEV_MAX_RULESET_LEN) == FMEV_MAX_RULESET_LEN)
		return (0);

	if (alloc == B_FALSE) {
		s = ruleset;
		ns = strsep(&s, FMEV_RS_SEPARATOR);

		if (s == NULL || s == ns + 1)
			return (0);
	} else {
		if ((s = strstr(ruleset, FMEV_RS_SEPARATOR)) == NULL ||
		    s == ruleset + strlen(ruleset) - 1)
			return (0);

		len = s - ruleset;

		ns = fmd_hdl_alloc(hdl, len + 1, FMD_SLEEP);
		(void) strncpy(ns, ruleset, len);
		ns[len] = '\0';

		s++;
	}

	if (nsp)
		*nsp = ns;	/* caller must free if alloc == B_TRUE */

	if (subsysp)
		*subsysp = s;	/* always within original ruleset string */

	return (1);
}