コード例 #1
0
ファイル: npf_ctl.c プロジェクト: zoltan/npf-gsoc-2012
static int __noinline
npf_mk_rules(npf_ruleset_t *rlset, prop_array_t rules, prop_array_t rprocs,
    prop_dictionary_t errdict)
{
	prop_object_iterator_t it;
	prop_dictionary_t rldict, rpdict;
	int error;

	/* Rule procedures and the ruleset - arrays. */
	if (prop_object_type(rprocs) != PROP_TYPE_ARRAY ||
	    prop_object_type(rules) != PROP_TYPE_ARRAY) {
		NPF_ERR_DEBUG(errdict);
		return EINVAL;
	}

	it = prop_array_iterator(rprocs);
	while ((rpdict = prop_object_iterator_next(it)) != NULL) {
		if (prop_dictionary_get(rpdict, "rproc-ptr")) {
			prop_object_iterator_release(it);
			NPF_ERR_DEBUG(errdict);
			return EINVAL;
		}
	}
	prop_object_iterator_release(it);

	error = 0;
	it = prop_array_iterator(rules);
	while ((rldict = prop_object_iterator_next(it)) != NULL) {
		prop_array_t subrules;
		npf_ruleset_t *rlsetsub;
		npf_rule_t *rl;

		/* Generate a single rule. */
		error = npf_mk_singlerule(rldict, rprocs, &rl, errdict);
		if (error) {
			break;
		}
		npf_ruleset_insert(rlset, rl);

		/* Check for sub-rules and generate, if any. */
		subrules = prop_dictionary_get(rldict, "subrules");
		if (subrules == NULL) {
			/* No subrules, next.. */
			continue;
		}
		rlsetsub = npf_rule_subset(rl);
		error = npf_mk_subrules(rlsetsub, subrules, rprocs, errdict);
		if (error)
			break;
	}
	prop_object_iterator_release(it);
	/*
	 * Note: in a case of error, caller will free the ruleset.
	 */
	return error;
}
コード例 #2
0
ファイル: npf_ctl.c プロジェクト: zoltan/npf-gsoc-2012
static npf_rproc_t *
npf_mk_rproc(prop_array_t rprocs, const char *rpname)
{
	prop_object_iterator_t it;
	prop_dictionary_t rpdict;
	npf_rproc_t *rp;
	uint64_t rpval;

	it = prop_array_iterator(rprocs);
	while ((rpdict = prop_object_iterator_next(it)) != NULL) {
		const char *iname;
		prop_dictionary_get_cstring_nocopy(rpdict, "name", &iname);
		KASSERT(iname != NULL);
		if (strcmp(rpname, iname) == 0)
			break;
	}
	prop_object_iterator_release(it);
	if (rpdict == NULL) {
		return NULL;
	}
	CTASSERT(sizeof(uintptr_t) <= sizeof(uint64_t));
	if (!prop_dictionary_get_uint64(rpdict, "rproc-ptr", &rpval)) {
		rp = npf_rproc_create(rpdict);
		rpval = (uint64_t)(uintptr_t)rp;
		prop_dictionary_set_uint64(rpdict, "rproc-ptr", rpval);
	} else {
		rp = (npf_rproc_t *)(uintptr_t)rpval;
	}
	return rp;
}
コード例 #3
0
ファイル: npf_ctl.c プロジェクト: yazshel/netbsd-kernel
static int __noinline
npf_mk_table_entries(npf_table_t *t, prop_array_t entries)
{
	prop_object_iterator_t eit;
	prop_dictionary_t ent;
	int error = 0;

	if (prop_object_type(entries) != PROP_TYPE_ARRAY) {
		return EINVAL;
	}
	eit = prop_array_iterator(entries);
	while ((ent = prop_object_iterator_next(eit)) != NULL) {
		const npf_addr_t *addr;
		npf_netmask_t mask;
		int alen;

		/* Get address and mask.  Add a table entry. */
		prop_object_t obj = prop_dictionary_get(ent, "addr");
		addr = (const npf_addr_t *)prop_data_data_nocopy(obj);
		prop_dictionary_get_uint8(ent, "mask", &mask);
		alen = prop_data_size(obj);

		error = npf_table_insert(t, alen, addr, mask);
		if (error)
			break;
	}
	prop_object_iterator_release(eit);
	return error;
}
コード例 #4
0
ファイル: npf_ctl.c プロジェクト: yazshel/netbsd-kernel
static int __noinline
npf_mk_rules(npf_ruleset_t *rlset, prop_array_t rules, npf_rprocset_t *rpset,
    prop_dictionary_t errdict)
{
	prop_object_iterator_t it;
	prop_dictionary_t rldict;
	int error;

	if (prop_object_type(rules) != PROP_TYPE_ARRAY) {
		NPF_ERR_DEBUG(errdict);
		return EINVAL;
	}

	error = 0;
	it = prop_array_iterator(rules);
	while ((rldict = prop_object_iterator_next(it)) != NULL) {
		npf_rule_t *rl = NULL;

		/* Generate a single rule. */
		error = npf_mk_singlerule(rldict, rpset, &rl, errdict);
		if (error) {
			break;
		}
		npf_ruleset_insert(rlset, rl);
	}
	prop_object_iterator_release(it);
	/*
	 * Note: in a case of error, caller will free the ruleset.
	 */
	return error;
}
コード例 #5
0
ファイル: npf_ctl.c プロジェクト: yazshel/netbsd-kernel
static npf_rproc_t *
npf_mk_singlerproc(prop_dictionary_t rpdict)
{
	prop_object_iterator_t it;
	prop_dictionary_t extdict;
	prop_array_t extlist;
	npf_rproc_t *rp;

	extlist = prop_dictionary_get(rpdict, "extcalls");
	if (prop_object_type(extlist) != PROP_TYPE_ARRAY) {
		return NULL;
	}

	rp = npf_rproc_create(rpdict);
	if (rp == NULL) {
		return NULL;
	}

	it = prop_array_iterator(extlist);
	while ((extdict = prop_object_iterator_next(it)) != NULL) {
		const char *name;

		if (!prop_dictionary_get_cstring_nocopy(extdict,
		    "name", &name) || npf_ext_construct(name, rp, extdict)) {
			npf_rproc_release(rp);
			rp = NULL;
			break;
		}
	}
	prop_object_iterator_release(it);
	return rp;
}
コード例 #6
0
static void
_npf_ruleset_transform1(prop_array_t rlset, prop_array_t rules)
{
	prop_object_iterator_t it;
	prop_dictionary_t rldict;
	prop_array_t subrlset;

	it = prop_array_iterator(rules);
	while ((rldict = prop_object_iterator_next(it)) != NULL) {
		unsigned idx;

		/* Add rules to the array (reference is retained). */
		prop_array_add(rlset, rldict);

		subrlset = prop_dictionary_get(rldict, "subrules");
		if (subrlset) {
			/* Process subrules recursively. */
			_npf_ruleset_transform1(rlset, subrlset);
			/* Add the skip-to position. */
			idx = prop_array_count(rlset);
			prop_dictionary_set_uint32(rldict, "skip-to", idx);
			prop_dictionary_remove(rldict, "subrules");
		}
	}
	prop_object_iterator_release(it);
}
コード例 #7
0
ファイル: npf_ctl.c プロジェクト: zoltan/npf-gsoc-2012
/*
 * npfctl_sessions_load: import a list of sessions, reconstruct them and load.
 */
int
npfctl_sessions_load(u_long cmd, void *data)
{
	const struct plistref *pref = data;
	npf_sehash_t *sehasht = NULL;
	prop_dictionary_t sesdict, sedict;
	prop_object_iterator_t it;
	prop_array_t selist;
	int error;

	/* Retrieve the dictionary containing session and NAT policy lists. */
	error = prop_dictionary_copyin_ioctl(pref, cmd, &sesdict);
	if (error)
		return error;

	/*
	 * Note: session objects contain the references to the NAT policy
	 * entries.  Therefore, no need to directly access it.
	 */
	selist = prop_dictionary_get(sesdict, "session-list");
	if (prop_object_type(selist) != PROP_TYPE_ARRAY) {
		error = EINVAL;
		goto fail;
	}

	/* Create a session hash table. */
	sehasht = sess_htable_create();
	if (sehasht == NULL) {
		error = ENOMEM;
		goto fail;
	}

	/*
	 * Iterate through and construct each session.
	 */
	error = 0;
	it = prop_array_iterator(selist);
	npf_core_enter();
	while ((sedict = prop_object_iterator_next(it)) != NULL) {
		/* Session - dictionary. */
		if (prop_object_type(sedict) != PROP_TYPE_DICTIONARY) {
			error = EINVAL;
			goto fail;
		}
		/* Construct and insert real session structure. */
		error = npf_session_restore(sehasht, sedict);
		if (error) {
			goto fail;
		}
	}
	npf_core_exit();
	sess_htable_reload(sehasht);
fail:
	prop_object_release(selist);
	if (error && sehasht) {
		/* Destroy session table. */
		sess_htable_destroy(sehasht);
	}
	return error;
}
コード例 #8
0
static nl_rule_t *
_npf_rule_iterate1(nl_config_t *ncf, prop_array_t rlist, unsigned *level)
{
	prop_dictionary_t rldict;
	uint32_t skipto = 0;

	if (!ncf->ncf_rule_iter) {
		/* Initialise the iterator. */
		ncf->ncf_rule_iter = prop_array_iterator(rlist);
		ncf->ncf_nlevel = 0;
		ncf->ncf_reduce[0] = 0;
		ncf->ncf_counter = 0;
	}

	rldict = prop_object_iterator_next(ncf->ncf_rule_iter);
	if ((ncf->ncf_cur_rule.nrl_dict = rldict) == NULL) {
		prop_object_iterator_release(ncf->ncf_rule_iter);
		ncf->ncf_rule_iter = NULL;
		return NULL;
	}
	*level = ncf->ncf_nlevel;

	prop_dictionary_get_uint32(rldict, "skip-to", &skipto);
	if (skipto) {
		ncf->ncf_nlevel++;
		ncf->ncf_reduce[ncf->ncf_nlevel] = skipto;
	}
	if (ncf->ncf_reduce[ncf->ncf_nlevel] == ++ncf->ncf_counter) {
		assert(ncf->ncf_nlevel > 0);
		ncf->ncf_nlevel--;
	}
	return &ncf->ncf_cur_rule;
}
コード例 #9
0
ファイル: npf_ctl.c プロジェクト: yazshel/netbsd-kernel
static int __noinline
npf_mk_natlist(npf_ruleset_t *nset, prop_array_t natlist,
    prop_dictionary_t errdict)
{
	prop_object_iterator_t it;
	prop_dictionary_t natdict;
	int error;

	/* NAT policies - array. */
	if (prop_object_type(natlist) != PROP_TYPE_ARRAY) {
		NPF_ERR_DEBUG(errdict);
		return EINVAL;
	}

	error = 0;
	it = prop_array_iterator(natlist);
	while ((natdict = prop_object_iterator_next(it)) != NULL) {
		npf_rule_t *rl = NULL;
		npf_natpolicy_t *np;

		/* NAT policy - dictionary. */
		if (prop_object_type(natdict) != PROP_TYPE_DICTIONARY) {
			NPF_ERR_DEBUG(errdict);
			error = EINVAL;
			break;
		}

		/*
		 * NAT policies are standard rules, plus additional
		 * information for translation.  Make a rule.
		 */
		error = npf_mk_singlerule(natdict, NULL, &rl, errdict);
		if (error) {
			break;
		}
		npf_ruleset_insert(nset, rl);

		/* If rule is named, it is a group with NAT policies. */
		if (prop_dictionary_get(natdict, "name") &&
		    prop_dictionary_get(natdict, "subrules")) {
			continue;
		}

		/* Allocate a new NAT policy and assign to the rule. */
		np = npf_nat_newpolicy(natdict, nset);
		if (np == NULL) {
			NPF_ERR_DEBUG(errdict);
			error = ENOMEM;
			break;
		}
		npf_rule_setnat(rl, np);
	}
	prop_object_iterator_release(it);
	/*
	 * Note: in a case of error, caller will free entire NAT ruleset
	 * with assigned NAT policies.
	 */
	return error;
}
コード例 #10
0
ファイル: hdaudioctl.c プロジェクト: ryo/netbsd-src
static int
hdaudioctl_list(int fd)
{
	prop_dictionary_t request, response;
	prop_dictionary_t dict;
	prop_object_iterator_t iter;
	prop_object_t obj;
	prop_array_t array;
	uint16_t nid, codecid;
	uint16_t vendor, product;
	uint32_t subsystem;
	const char *device = NULL;
	int error;

	request = prop_dictionary_create();
	if (request == NULL) {
		fprintf(stderr, "out of memory\n");
		return ENOMEM;
	}

	error = prop_dictionary_sendrecv_ioctl(request, fd,
	    HDAUDIO_FGRP_INFO, &response);
	if (error != 0) {
		perror("HDAUDIO_FGRP_INFO failed");
		return error;
	}

	array = prop_dictionary_get(response, "function-group-info");
	iter = prop_array_iterator(array);
	prop_object_iterator_reset(iter);
	while ((obj = prop_object_iterator_next(iter)) != NULL) {
		dict = (prop_dictionary_t)obj;
		prop_dictionary_get_uint16(dict, "codecid", &codecid);
		prop_dictionary_get_uint16(dict, "nid", &nid);
		prop_dictionary_get_uint16(dict, "vendor-id", &vendor);
		prop_dictionary_get_uint16(dict, "product-id", &product);
		prop_dictionary_get_uint32(dict, "subsystem-id", &subsystem);
		prop_dictionary_get_cstring_nocopy(dict, "device", &device);

		printf("codecid 0x%02X nid 0x%02X vendor 0x%04X "
		    "product 0x%04X subsystem 0x%08X device %s\n",
		    codecid, nid, vendor, product, subsystem,
		    device ? device : "<none>");
	}

	prop_object_release(array);
	prop_object_release(response);
	prop_object_release(request);

	return 0;
}
コード例 #11
0
static bool
_npf_prop_array_lookup(prop_array_t array, const char *key, const char *name)
{
	prop_dictionary_t dict;
	prop_object_iterator_t it;

	it = prop_array_iterator(array);
	while ((dict = prop_object_iterator_next(it)) != NULL) {
		const char *lname;
		prop_dictionary_get_cstring_nocopy(dict, key, &lname);
		if (strcmp(name, lname) == 0)
			break;
	}
	prop_object_iterator_release(it);
	return dict ? true : false;
}
コード例 #12
0
ファイル: ufs_vfsops.c プロジェクト: AgamAgarwal/minix
/*
 * Do operations associated with quotas
 */
int
ufs_quotactl(struct mount *mp, prop_dictionary_t dict)
{
	struct lwp *l = curlwp;

#if !defined(QUOTA) && !defined(QUOTA2)
	(void) mp;
	(void) dict;
	(void) l;
	return (EOPNOTSUPP);
#else
	int  error;
	prop_dictionary_t cmddict;
	prop_array_t commands;
	prop_object_iterator_t iter;

	/* Mark the mount busy, as we're passing it to kauth(9). */
	error = vfs_busy(mp, NULL);
	if (error)
		return (error);

	error = quota_get_cmds(dict, &commands);
	if (error)
		goto out_vfs;
	iter = prop_array_iterator(commands);
	if (iter == NULL) {
		error = ENOMEM;
		goto out_vfs;
	}
		
		
	mutex_enter(&mp->mnt_updating);
	while ((cmddict = prop_object_iterator_next(iter)) != NULL) {
		if (prop_object_type(cmddict) != PROP_TYPE_DICTIONARY)
			continue;
		error = quota_handle_cmd(mp, l, cmddict);
		if (error)
			break;
	}
	prop_object_iterator_release(iter);
	mutex_exit(&mp->mnt_updating);
out_vfs:
	vfs_unbusy(mp, false, NULL);
	return (error);
#endif
}
コード例 #13
0
nl_rproc_t *
npf_rproc_iterate(nl_config_t *ncf)
{
	prop_dictionary_t rpdict;

	if (!ncf->ncf_rproc_iter) {
		/* Initialise the iterator. */
		ncf->ncf_rproc_iter = prop_array_iterator(ncf->ncf_rproc_list);
	}
	rpdict = prop_object_iterator_next(ncf->ncf_rproc_iter);
	if ((ncf->ncf_cur_rproc.nrp_dict = rpdict) == NULL) {
		prop_object_iterator_release(ncf->ncf_rproc_iter);
		ncf->ncf_rproc_iter = NULL;
		return NULL;
	}
	return &ncf->ncf_cur_rproc;
}
コード例 #14
0
nl_table_t *
npf_table_iterate(nl_config_t *ncf)
{
	prop_dictionary_t tldict;

	if (!ncf->ncf_table_iter) {
		/* Initialise the iterator. */
		ncf->ncf_table_iter = prop_array_iterator(ncf->ncf_table_list);
	}
	tldict = prop_object_iterator_next(ncf->ncf_table_iter);
	if ((ncf->ncf_cur_table.ntl_dict = tldict) == NULL) {
		prop_object_iterator_release(ncf->ncf_table_iter);
		ncf->ncf_table_iter = NULL;
		return NULL;
	}
	return &ncf->ncf_cur_table;
}
コード例 #15
0
static bool
_npf_table_exists_p(nl_config_t *ncf, const char *name)
{
	prop_dictionary_t tldict;
	prop_object_iterator_t it;

	it = prop_array_iterator(ncf->ncf_table_list);
	while ((tldict = prop_object_iterator_next(it)) != NULL) {
		const char *tname = NULL;

		if (prop_dictionary_get_cstring_nocopy(tldict, "name", &tname)
		    && strcmp(tname, name) == 0)
			break;
	}
	prop_object_iterator_release(it);
	return tldict ? true : false;
}
コード例 #16
0
ファイル: npf_ctl.c プロジェクト: yazshel/netbsd-kernel
static int __noinline
npf_mk_algs(prop_array_t alglist, prop_dictionary_t errdict)
{
	prop_object_iterator_t it;
	prop_dictionary_t nadict;
	int error = 0;

	it = prop_array_iterator(alglist);
	while ((nadict = prop_object_iterator_next(it)) != NULL) {
		if (npf_mk_singlealg(nadict) == NULL) {
			NPF_ERR_DEBUG(errdict);
			error = EINVAL;
			break;
		}
	}
	prop_object_iterator_release(it);
	return error;
}
コード例 #17
0
/*
 * Print dm device dependiences, get minor/major number for 
 * devices. From kernel I will receive major:minor number of 
 * block device used with target. I have to translate it to 
 * raw device numbers and use them, because all other parts of lvm2 
 * uses raw devices internaly.
 */
static int
dm_dev_deps(prop_dictionary_t dm_dict, struct dm_ioctl *dmi)
{
	struct dm_target_deps *dmtd;
	
	prop_array_t targets;
	prop_object_iterator_t iter;
	
	uint32_t major;
	
	size_t val_len, i, j;

	uint64_t dev_tmp;

	dev_tmp = 0;
	j = 0;
	i = 0;
	
	
	dmtd = (struct dm_target_deps *)((uint8_t *)dmi + dmi->data_start);

	if ((targets = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA))){

		iter = prop_array_iterator(targets);
		if (!iter)
			err(EXIT_FAILURE,"dm_target_deps %s", __func__);

		while((prop_object_iterator_next(iter)) != NULL){

			prop_array_get_uint64(targets, j, &dev_tmp);

			dmtd->dev[j] = MKDEV(MAJOR(dev_tmp),MINOR(dev_tmp));
			/* XXX: worth revisiting */
			j++;
		}
	}	
	
	dmtd->count = j;

	prop_object_iterator_release(iter);
	
	return j;
}
コード例 #18
0
ファイル: npf_ctl.c プロジェクト: yazshel/netbsd-kernel
/*
 * npf_mk_connlist: import a list of connections and load them.
 */
static int __noinline
npf_mk_connlist(prop_array_t conlist, npf_ruleset_t *natlist,
    npf_conndb_t **conndb, prop_dictionary_t errdict)
{
	prop_dictionary_t condict;
	prop_object_iterator_t it;
	npf_conndb_t *cd;
	int error = 0;

	/* Connection list - array */
	if (prop_object_type(conlist) != PROP_TYPE_ARRAY) {
		NPF_ERR_DEBUG(errdict);
		return EINVAL;
	}

	/* Create a connection database. */
	cd = npf_conndb_create();
	it = prop_array_iterator(conlist);
	while ((condict = prop_object_iterator_next(it)) != NULL) {
		/* Connection - dictionary. */
		if (prop_object_type(condict) != PROP_TYPE_DICTIONARY) {
			NPF_ERR_DEBUG(errdict);
			error = EINVAL;
			break;
		}
		/* Construct and insert the connection. */
		error = npf_conn_import(cd, condict, natlist);
		if (error) {
			NPF_ERR_DEBUG(errdict);
			break;
		}
	}
	prop_object_iterator_release(it);
	if (error) {
		npf_conn_gc(cd, true, false);
		npf_conndb_destroy(cd);
	} else {
		*conndb = cd;
	}
	return error;
}
コード例 #19
0
ファイル: udevd.c プロジェクト: alexandermerritt/dragonfly
prop_dictionary_t
find_dev_dict(int64_t generation, prop_dictionary_t match_dict, int *idx)
{
	struct pdev_array_entry	*pae;
	prop_array_t		pa;
	prop_object_iterator_t	iter;
	prop_dictionary_t	dict;
	int i = 0;

	if (generation == -1)
		pae = pdev_array_entry_get_last();
	else
		pae = pdev_array_entry_get(generation);

	if (pae == NULL)
		return NULL;

	pa = pae->pdev_array;

	iter = prop_array_iterator(pa);
	if (iter == NULL) {
		pdev_array_entry_unref(pae);
		return NULL;
	}

	while ((dict = prop_object_iterator_next(iter)) != NULL) {
		if (match_dev_dict(dict, match_dict))
			break;
		++i;
	}

	prop_object_iterator_release(iter);

	if (idx != NULL)
		*idx = i;

	pdev_array_entry_unref(pae);
	return dict;
}
コード例 #20
0
ファイル: npf_ctl.c プロジェクト: yazshel/netbsd-kernel
static int __noinline
npf_mk_rprocs(npf_rprocset_t *rpset, prop_array_t rprocs,
    prop_dictionary_t errdict)
{
	prop_object_iterator_t it;
	prop_dictionary_t rpdict;
	int error = 0;

	it = prop_array_iterator(rprocs);
	while ((rpdict = prop_object_iterator_next(it)) != NULL) {
		npf_rproc_t *rp;

		if ((rp = npf_mk_singlerproc(rpdict)) == NULL) {
			NPF_ERR_DEBUG(errdict);
			error = EINVAL;
			break;
		}
		npf_rprocset_insert(rpset, rp);
	}
	prop_object_iterator_release(it);
	return error;
}
コード例 #21
0
ファイル: npf_ctl.c プロジェクト: zoltan/npf-gsoc-2012
static int __noinline
npf_mk_subrules(npf_ruleset_t *rlset, prop_array_t rules, prop_array_t rprocs,
    prop_dictionary_t errdict)
{
	prop_object_iterator_t it;
	prop_dictionary_t rldict;
	int error = 0;

	if (prop_object_type(rules) != PROP_TYPE_ARRAY) {
		NPF_ERR_DEBUG(errdict);
		return EINVAL;
	}
	it = prop_array_iterator(rules);
	while ((rldict = prop_object_iterator_next(it)) != NULL) {
		npf_rule_t *rl;
		error = npf_mk_singlerule(rldict, rprocs, &rl, errdict);
		if (error) {
			break;
		}
		npf_ruleset_insert(rlset, rl);
	}
	prop_object_iterator_release(it);
	return error;
}
コード例 #22
0
static int
dm_list_versions(prop_dictionary_t dm_dict, struct dm_ioctl *dmi)
{
	struct dm_target_versions *dmtv,*odmtv;

	prop_array_t targets,ver;
	prop_dictionary_t target_dict;
	prop_object_iterator_t iter;
	
	char *name;
	size_t j,i,slen,rec_size;
	
	odmtv = NULL;
	name = NULL;
	j = 0;
	
	dmtv = (struct dm_target_versions *)((uint8_t *)dmi + dmi->data_start);

/*	printf("dmi: vers: %d.%d.%d data_size: %d data_start: %d name: %s t_count: %d\n",
	    dmi->version[0],dmi->version[1],dmi->version[2],dmi->data_size,dmi->data_start,
	    dmi->name,dmi->target_count);

	printf("dmi: size: %d -- %p --- %p \n",sizeof(struct dm_ioctl),dmi,dmi+dmi->data_start);
	printf("dmtv: size: %p --- %p\n",dmtv,(struct dm_target_versions *)(dmi+312));*/

	/* get prop_array of target_version dictionaries */
	if ((targets = prop_dictionary_get(dm_dict,DM_IOCTL_CMD_DATA))){

		iter = prop_array_iterator(targets);
		if (!iter)
			err(EXIT_FAILURE,"dm_list_versions %s",__func__);

		while((target_dict = prop_object_iterator_next(iter)) != NULL){
			j++;
	
			prop_dictionary_get_cstring_nocopy(target_dict,
			    DM_TARGETS_NAME,(const char **)&name);
			
			slen = strlen(name) + 1;
			rec_size = sizeof(struct dm_target_versions) + slen + 1;

			if (rec_size > dmi->data_size)
				return -ENOMEM;
			
			ver = prop_dictionary_get(target_dict,DM_TARGETS_VERSION);
						
			for (i=0; i<3; i++)
				prop_array_get_uint32(ver,i,&dmtv->version[i]);

			dmtv->next = rec_size;

			strlcpy(dmtv->name,name,slen);

			odmtv = dmtv;
			
			dmtv =(struct dm_target_versions *)((uint8_t *)dmtv + rec_size);
		}

		if (odmtv != NULL)
			odmtv->next = 0;
	}			

	prop_object_iterator_release(iter);
	return j;
}
コード例 #23
0
ファイル: dm_ioctl.c プロジェクト: AhmadTux/DragonFlyBSD
/*
 * Load new table/tables to device.
 * Call apropriate target init routine open all physical pdev's and
 * link them to device. For other targets mirror, strip, snapshot
 * etc. also add dependency devices to upcalls list.
 *
 * Load table to inactive slot table are switched in dm_device_resume_ioctl.
 * This simulates Linux behaviour better there should not be any difference.
 *
 */
int
dm_table_load_ioctl(prop_dictionary_t dm_dict)
{
	dm_dev_t *dmv;
	dm_table_entry_t *table_en, *last_table;
	dm_table_t *tbl;
	dm_target_t *target;

	prop_object_iterator_t iter;
	prop_array_t cmd_array;
	prop_dictionary_t target_dict;

	const char *name, *uuid, *type;

	uint32_t flags, ret, minor;

	char *str;

	ret = 0;
	flags = 0;
	name = NULL;
	uuid = NULL;
	dmv = NULL;
	last_table = NULL;
	str = NULL;

	/*
	 * char *xml; xml = prop_dictionary_externalize(dm_dict);
	 * printf("%s\n",xml);
	 */

	prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_NAME, &name);
	prop_dictionary_get_cstring_nocopy(dm_dict, DM_IOCTL_UUID, &uuid);
	prop_dictionary_get_uint32(dm_dict, DM_IOCTL_FLAGS, &flags);
	prop_dictionary_get_uint32(dm_dict, DM_IOCTL_MINOR, &minor);

	cmd_array = prop_dictionary_get(dm_dict, DM_IOCTL_CMD_DATA);
	iter = prop_array_iterator(cmd_array);
	dm_dbg_print_flags(flags);

	if ((dmv = dm_dev_lookup(name, uuid, minor)) == NULL) {
		DM_REMOVE_FLAG(flags, DM_EXISTS_FLAG);
		return ENOENT;
	}
	aprint_debug("Loading table to device: %s--%d\n", name,
	    dmv->table_head.cur_active_table);

	/*
	 * I have to check if this table slot is not used by another table list.
	 * if it is used I should free them.
	 */
	if (dmv->flags & DM_INACTIVE_PRESENT_FLAG)
		dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);

	dm_dbg_print_flags(dmv->flags);
	tbl = dm_table_get_entry(&dmv->table_head, DM_TABLE_INACTIVE);

	aprint_debug("dmv->name = %s\n", dmv->name);

	prop_dictionary_set_uint32(dm_dict, DM_IOCTL_MINOR, dmv->minor);

	while ((target_dict = prop_object_iterator_next(iter)) != NULL) {
		prop_dictionary_get_cstring_nocopy(target_dict,
		    DM_TABLE_TYPE, &type);
		/*
		 * If we want to deny table with 2 or more different
		 * target we should do it here
		 */
		if (((target = dm_target_lookup(type)) == NULL) &&
		    ((target = dm_target_autoload(type)) == NULL)) {
			dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
			dm_dev_unbusy(dmv);
			return ENOENT;
		}
		if ((table_en = kmalloc(sizeof(dm_table_entry_t),
			    M_DM, M_WAITOK)) == NULL) {
			dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
			dm_dev_unbusy(dmv);
			dm_target_unbusy(target);
			return ENOMEM;
		}
		prop_dictionary_get_uint64(target_dict, DM_TABLE_START,
		    &table_en->start);
		prop_dictionary_get_uint64(target_dict, DM_TABLE_LENGTH,
		    &table_en->length);

		aprint_debug("dm_ioctl.c... table_en->start = %ju, "
			     "table_en->length = %ju\n",
			     (uintmax_t)table_en->start,
			     (uintmax_t)table_en->length);

		table_en->target = target;
		table_en->dm_dev = dmv;
		table_en->target_config = NULL;

		/*
		 * There is a parameter string after dm_target_spec
		 * structure which  points to /dev/wd0a 284 part of
		 * table. String str points to this text. This can be
		 * null and therefore it should be checked before we try to
		 * use it.
		 */
		prop_dictionary_get_cstring(target_dict,
		    DM_TABLE_PARAMS, &str);

		if (SLIST_EMPTY(tbl))
			/* insert this table to head */
			SLIST_INSERT_HEAD(tbl, table_en, next);
		else
			SLIST_INSERT_AFTER(last_table, table_en, next);

		/*
		 * Params string is different for every target,
		 * therfore I have to pass it to target init
		 * routine and parse parameters there.
		 */
		aprint_debug("DM: str passed in is: %s", str);
		if ((ret = target->init(dmv, &table_en->target_config,
			    str)) != 0) {

			dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);
			dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE);
			kfree(str, M_TEMP);

			dm_dev_unbusy(dmv);
			dm_target_unbusy(target);
			return ret;
		}
		last_table = table_en;
		kfree(str, M_TEMP);
	}
	prop_object_iterator_release(iter);

	DM_ADD_FLAG(flags, DM_INACTIVE_PRESENT_FLAG);
	atomic_set_int(&dmv->flags, DM_INACTIVE_PRESENT_FLAG);

	dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE);

	dm_dev_unbusy(dmv);
#if 0
	dmsetdiskinfo(dmv->diskp, &dmv->table_head);
#endif
	return 0;
}
コード例 #24
0
/*
 * Print status of each table, target arguments, start sector, 
 * size and target name.
 */
static int
dm_table_status(prop_dictionary_t dm_dict,struct dm_ioctl *dmi)
{
	struct dm_target_spec *dmts, *odmts;

	prop_array_t targets;
	prop_dictionary_t target_dict;
	prop_object_iterator_t iter;

	char *type,*params,*params_start;

	bool prm;
	size_t j,plen,rec_size,next;

	j = 0;
	next = 0;
	params = NULL;
	odmts = NULL;
	rec_size = 0;
	plen = -1;
	prm = false;
	
	dmts = (struct dm_target_spec *)((uint8_t *)dmi + dmi->data_start);	
		
	if ((targets = prop_dictionary_get(dm_dict,DM_IOCTL_CMD_DATA))){

		iter = prop_array_iterator(targets);
		if (!iter)
			err(EXIT_FAILURE,"dm_table_status %s",__func__);

		while((target_dict = prop_object_iterator_next(iter)) != NULL){

			prop_dictionary_get_cstring_nocopy(target_dict,
			    DM_TABLE_TYPE,(const char **)&type);

			prm = prop_dictionary_get_cstring_nocopy(target_dict,
			    DM_TABLE_PARAMS,(const char **)&params);

			prop_dictionary_get_uint64(target_dict,DM_TABLE_START,&dmts->sector_start);
			prop_dictionary_get_uint64(target_dict,DM_TABLE_LENGTH,&dmts->length);
			prop_dictionary_get_int32(target_dict,DM_TABLE_STAT,&dmts->status);

			if (prm)
				plen = strlen(params) + 1;

			rec_size = sizeof(struct dm_target_spec) + plen;

			/*
			 * In linux when copying table status from kernel next is
			 * number of bytes from the start of the first dm_target_spec
			 * structure. I don't know why but, it has to be done this way.
			 */
			next += rec_size; 
			
			if (rec_size > dmi->data_size)
				return -ENOMEM;

			dmts->next = next;
			
			strlcpy(dmts->target_type, type, DM_MAX_TYPE_NAME);

			params_start = (char *)dmts + sizeof(struct dm_target_spec);

			if (prm) 
				strlcpy(params_start, params, plen);
			else
				params_start = "\0";

			
			odmts = dmts;
			
			dmts = (struct dm_target_spec *)((uint8_t *)dmts + rec_size);

			j++;
			
		}

		if (odmts != NULL)
			odmts->next = 0;
	}			
	prop_object_iterator_release(iter);

	return j;
}
コード例 #25
0
ファイル: ufs_quota.c プロジェクト: AgamAgarwal/minix
static int 
quota_handle_cmd_get(struct mount *mp, struct lwp *l, 
    prop_dictionary_t cmddict, int type, prop_array_t datas)
{
	prop_array_t replies;
	prop_object_iterator_t iter;
	prop_dictionary_t data;
	uint32_t id;
	struct ufsmount *ump = VFSTOUFS(mp);
	int error, defaultq = 0;
	const char *idstr;

	if ((ump->um_flags & (UFS_QUOTA|UFS_QUOTA2)) == 0)
		return EOPNOTSUPP;
	
	replies = prop_array_create();
	if (replies == NULL)
		return ENOMEM;

	iter = prop_array_iterator(datas);
	if (iter == NULL) {
		prop_object_release(replies);
		return ENOMEM;
	}
	while ((data = prop_object_iterator_next(iter)) != NULL) {
		if (!prop_dictionary_get_uint32(data, "id", &id)) {
			if (!prop_dictionary_get_cstring_nocopy(data, "id",
			    &idstr))
				continue;
			if (strcmp(idstr, "default")) {
				error = EINVAL;
				goto err;
			}
			id = 0;
			defaultq = 1;
		} else {
			defaultq = 0;
		}
		error = quota_get_auth(mp, l, id);
		if (error == EPERM)
			continue;
		if (error != 0) 
			goto err;
#ifdef QUOTA
		if (ump->um_flags & UFS_QUOTA)
			error = quota1_handle_cmd_get(ump, type, id, defaultq,
			    replies);
		else
#endif
#ifdef QUOTA2
		if (ump->um_flags & UFS_QUOTA2) {
			error = quota2_handle_cmd_get(ump, type, id, defaultq,
			    replies);
		} else
#endif
			panic("quota_handle_cmd_get: no support ?");
		
		if (error == ENOENT)
			continue;
		if (error != 0)
			goto err;
	}
	prop_object_iterator_release(iter);
	if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) {
		error = ENOMEM;
	} else {
		error = 0;
	}
	return error;
err:
	prop_object_iterator_release(iter);
	prop_object_release(replies);
	return error;
}
コード例 #26
0
ファイル: npf_ctl.c プロジェクト: yazshel/netbsd-kernel
static int __noinline
npf_mk_tables(npf_tableset_t *tblset, prop_array_t tables,
    prop_dictionary_t errdict)
{
	prop_object_iterator_t it;
	prop_dictionary_t tbldict;
	int error = 0;

	/* Tables - array. */
	if (prop_object_type(tables) != PROP_TYPE_ARRAY) {
		NPF_ERR_DEBUG(errdict);
		return EINVAL;
	}

	it = prop_array_iterator(tables);
	while ((tbldict = prop_object_iterator_next(it)) != NULL) {
		const char *name;
		npf_table_t *t;
		u_int tid;
		int type;

		/* Table - dictionary. */
		if (prop_object_type(tbldict) != PROP_TYPE_DICTIONARY) {
			NPF_ERR_DEBUG(errdict);
			error = EINVAL;
			break;
		}

		/* Table name, ID and type.  Validate them. */
		if (!prop_dictionary_get_cstring_nocopy(tbldict, "name", &name)) {
			NPF_ERR_DEBUG(errdict);
			error = EINVAL;
			break;
		}
		prop_dictionary_get_uint32(tbldict, "id", &tid);
		prop_dictionary_get_int32(tbldict, "type", &type);
		error = npf_table_check(tblset, name, tid, type);
		if (error) {
			NPF_ERR_DEBUG(errdict);
			break;
		}

		/* Get the entries or binary data. */
		prop_array_t ents = prop_dictionary_get(tbldict, "entries");
		prop_object_t obj = prop_dictionary_get(tbldict, "data");
		void *blob = prop_data_data(obj);
		size_t size = prop_data_size(obj);

		if (type == NPF_TABLE_CDB && (blob == NULL || size == 0)) {
			NPF_ERR_DEBUG(errdict);
			error = EINVAL;
			break;
		}
		if (type == NPF_TABLE_HASH) {
			size = 1024; /* XXX */
		}

		/* Create and insert the table. */
		t = npf_table_create(name, tid, type, blob, size);
		if (t == NULL) {
			NPF_ERR_DEBUG(errdict);
			error = ENOMEM;
			break;
		}
		error = npf_tableset_insert(tblset, t);
		KASSERT(error == 0);

		if (ents && (error = npf_mk_table_entries(t, ents)) != 0) {
			NPF_ERR_DEBUG(errdict);
			break;
		}
	}
	prop_object_iterator_release(it);
	/*
	 * Note: in a case of error, caller will free the tableset.
	 */
	return error;
}
コード例 #27
0
int
main(int argc, char *argv[])
{
    int ch, nflag, status, x, verbose;
    static bstg_funcs_t bfs;
    char *buf;

    verbose = nflag = 0;
    while ((ch = getopt(argc, argv, "f:nv")) != -1) {
        switch (ch) {
            case 'n':
                nflag = 1;
                break;
            case 'v':
                verbose = 1;
                break;
            case '?':
            default:
                usage();
        }
    }
    argv += optind-1;

    if (nflag) {
        printf("%lu\n", NFUNCS);
        return 0;
    }

    if (bstg_funcs_init(&bfs, verbose, 1048576)) {
        errx(1, "cannot init bfs");
    }

    buf = BSTGNULLCHECK(malloc(65536));

    for (x = 0; x < 128; x++) {
        pid_t pid;

        pid = fork();
        if (pid == 0) {
            srand(x);

            while (*argv++) {
                struct archive *a;
                struct archive_entry *entry;

                a = archive_read_new();
                archive_read_support_format_all(a);
                archive_read_support_filter_all(a);
                if (archive_read_open_filename(a, *argv, 10240)) {
                    _exit(2);
                }
                while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
                    size_t size;

                    size = archive_entry_size(entry);
                    buf = BSTGNULLCHECK(realloc(buf, size+1024));
                    if (archive_read_data(a, buf, size) == size) {
                        prop_array_t ops;
                        prop_number_t op;
                        prop_object_iterator_t it;
                        unsigned id;

                        /* zero terminate the file from the archive */
                        strlcat(buf, "", 1);

                        ops = BSTGNULLCHECK((prop_array_internalize(buf)));
                        it = BSTGNULLCHECK(prop_array_iterator(ops));
                        while ((op = prop_object_iterator_next(it)) != NULL) {
                            id = prop_number_unsigned_integer_value(op);
                            (*bstg_fembot_funcs[id % NFUNCS]) (&bfs);
                        }
                        prop_object_iterator_release(it);
                        prop_object_release(ops);
                    }
                }
                archive_read_close(a);
                archive_read_free(a);
            }

            if (bstg_funcs_destroy(&bfs)) {
                errx(1, "cannot destroy bfs");
            }

            _exit(1);
        }
    }

    while(wait(&status) > 0);
    while(wait(&status) > 0);
    while(wait(&status) > 0);

    if (bstg_funcs_destroy(&bfs)) {
        errx(1, "cannot destroy bfs");
    }

    return 0;
}
コード例 #28
0
ファイル: ufs_quota.c プロジェクト: AgamAgarwal/minix
static int 
quota_handle_cmd_clear(struct mount *mp, struct lwp *l, 
    prop_dictionary_t cmddict, int type, prop_array_t datas)
{
	prop_array_t replies;
	prop_object_iterator_t iter;
	prop_dictionary_t data;
	uint32_t id;
	struct ufsmount *ump = VFSTOUFS(mp);
	int error, defaultq = 0;
	const char *idstr;

	if ((ump->um_flags & UFS_QUOTA2) == 0)
		return EOPNOTSUPP;
	
	replies = prop_array_create();
	if (replies == NULL)
		return ENOMEM;

	iter = prop_array_iterator(datas);
	if (iter == NULL) {
		prop_object_release(replies);
		return ENOMEM;
	}
	while ((data = prop_object_iterator_next(iter)) != NULL) {
		if (!prop_dictionary_get_uint32(data, "id", &id)) {
			if (!prop_dictionary_get_cstring_nocopy(data, "id",
			    &idstr))
				continue;
			if (strcmp(idstr, "default"))
				continue;
			id = 0;
			defaultq = 1;
		} else {
			defaultq = 0;
		}
		error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
		    KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE, mp, KAUTH_ARG(id), NULL);
		if (error != 0)
			goto err;
#ifdef QUOTA2
		if (ump->um_flags & UFS_QUOTA2) {
			error = quota2_handle_cmd_clear(ump, type, id, defaultq,
			    data);
		} else
#endif
			panic("quota_handle_cmd_get: no support ?");
		
		if (error && error != ENOENT)
			goto err;
	}
	prop_object_iterator_release(iter);
	if (!prop_dictionary_set_and_rel(cmddict, "data", replies)) {
		error = ENOMEM;
	} else {
		error = 0;
	}
	return error;
err:
	prop_object_iterator_release(iter);
	prop_object_release(replies);
	return error;
}
コード例 #29
0
/*
 * Reads the CPU temperature from /sys/class/thermal/thermal_zone%d/temp (or
 * the user provided path) and returns the temperature in degree celcius.
 *
 */
void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const char *path, const char *format, int max_threshold) {
    char *outwalk = buffer;
#ifdef THERMAL_ZONE
    const char *walk;
    bool colorful_output = false;
    char *thermal_zone;

    if (path == NULL)
        asprintf(&thermal_zone, THERMAL_ZONE, zone);
    else {
        static glob_t globbuf;
        if (glob(path, GLOB_NOCHECK | GLOB_TILDE, NULL, &globbuf) < 0)
            die("glob() failed\n");
        if (globbuf.gl_pathc == 0) {
            /* No glob matches, the specified path does not contain a wildcard. */
            asprintf(&thermal_zone, path, zone);
        } else {
            /* glob matched, we take the first match and ignore the others */
            asprintf(&thermal_zone, "%s", globbuf.gl_pathv[0]);
        }
        globfree(&globbuf);
    }

    INSTANCE(thermal_zone);

    for (walk = format; *walk != '\0'; walk++) {
        if (*walk != '%') {
            *(outwalk++) = *walk;
            continue;
        }

        if (BEGINS_WITH(walk + 1, "degrees")) {
#if defined(LINUX)
            static char buf[16];
            long int temp;
            if (!slurp(thermal_zone, buf, sizeof(buf)))
                goto error;
            temp = strtol(buf, NULL, 10);
            if (temp == LONG_MIN || temp == LONG_MAX || temp <= 0)
                *(outwalk++) = '?';
            else {
                if ((temp / 1000) >= max_threshold) {
                    START_COLOR("color_bad");
                    colorful_output = true;
                }
                outwalk += sprintf(outwalk, "%ld", (temp / 1000));
                if (colorful_output) {
                    END_COLOR;
                    colorful_output = false;
                }
            }
#elif defined(__DragonFly__)
            struct sensor th_sensor;
            size_t th_sensorlen;

            th_sensorlen = sizeof(th_sensor);

            if (sysctlbyname(thermal_zone, &th_sensor, &th_sensorlen, NULL, 0) == -1) {
                perror("sysctlbyname");
                goto error;
            }
            if (MUKTOC(th_sensor.value) >= max_threshold) {
                START_COLOR("color_bad");
                colorful_output = true;
            }
            outwalk += sprintf(outwalk, "%.2f", MUKTOC(th_sensor.value));
            if (colorful_output) {
                END_COLOR;
                colorful_output = false;
            }

#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
            int sysctl_rslt;
            size_t sysctl_size = sizeof(sysctl_rslt);
            if (sysctlbyname(thermal_zone, &sysctl_rslt, &sysctl_size, NULL, 0))
                goto error;

            if (TZ_AVG(sysctl_rslt) >= max_threshold) {
                START_COLOR("color_bad");
                colorful_output = true;
            }
            outwalk += sprintf(outwalk, "%d.%d", TZ_KELVTOC(sysctl_rslt));
            if (colorful_output) {
                END_COLOR;
                colorful_output = false;
            }

#elif defined(__OpenBSD__)
            struct sensordev sensordev;
            struct sensor sensor;
            size_t sdlen, slen;
            int dev, numt, mib[5] = {CTL_HW, HW_SENSORS, 0, 0, 0};

            sdlen = sizeof(sensordev);
            slen = sizeof(sensor);

            for (dev = 0;; dev++) {
                mib[2] = dev;
                if (sysctl(mib, 3, &sensordev, &sdlen, NULL, 0) == -1) {
                    if (errno == ENXIO)
                        continue;
                    if (errno == ENOENT)
                        break;
                    goto error;
                }
                /* 'path' is the node within the full path (defaults to acpitz0). */
                if (BEGINS_WITH(sensordev.xname, thermal_zone)) {
                    mib[3] = SENSOR_TEMP;
                    /* Limit to temo0, but should retrieve from a full path... */
                    for (numt = 0; numt < 1 /*sensordev.maxnumt[SENSOR_TEMP]*/; numt++) {
                        mib[4] = numt;
                        if (sysctl(mib, 5, &sensor, &slen, NULL, 0) == -1) {
                            if (errno != ENOENT) {
                                warn("sysctl");
                                continue;
                            }
                        }
                        if ((int)MUKTOC(sensor.value) >= max_threshold) {
                            START_COLOR("color_bad");
                            colorful_output = true;
                        }

                        outwalk += sprintf(outwalk, "%.2f", MUKTOC(sensor.value));

                        if (colorful_output) {
                            END_COLOR;
                            colorful_output = false;
                        }
                    }
                }
            }
#elif defined(__NetBSD__)
            int fd, rval;
            bool err = false;
            prop_dictionary_t dict;
            prop_array_t array;
            prop_object_iterator_t iter;
            prop_object_iterator_t iter2;
            prop_object_t obj, obj2, obj3;

            fd = open("/dev/sysmon", O_RDONLY);
            if (fd == -1)
                goto error;

            rval = prop_dictionary_recv_ioctl(fd, ENVSYS_GETDICTIONARY, &dict);
            if (rval == -1) {
                err = true;
                goto error_netbsd1;
            }

            /* No drivers registered? */
            if (prop_dictionary_count(dict) == 0) {
                err = true;
                goto error_netbsd2;
            }

            iter = prop_dictionary_iterator(dict);
            if (iter == NULL) {
                err = true;
                goto error_netbsd2;
            }

            /* iterate over the dictionary returned by the kernel */
            while ((obj = prop_object_iterator_next(iter)) != NULL) {
                /* skip this dict if it's not what we're looking for */
                if ((strlen(prop_dictionary_keysym_cstring_nocopy(obj)) != strlen(thermal_zone)) ||
                    (strncmp(thermal_zone,
                             prop_dictionary_keysym_cstring_nocopy(obj),
                             strlen(thermal_zone)) != 0))
                    continue;

                array = prop_dictionary_get_keysym(dict, obj);
                if (prop_object_type(array) != PROP_TYPE_ARRAY) {
                    err = true;
                    goto error_netbsd3;
                }

                iter2 = prop_array_iterator(array);
                if (!iter2) {
                    err = true;
                    goto error_netbsd3;
                }

                /* iterate over array of dicts specific to target sensor */
                while ((obj2 = prop_object_iterator_next(iter2)) != NULL) {
                    obj3 = prop_dictionary_get(obj2, "cur-value");

                    float temp = MUKTOC(prop_number_integer_value(obj3));
                    if ((int)temp >= max_threshold) {
                        START_COLOR("color_bad");
                        colorful_output = true;
                    }

                    outwalk += sprintf(outwalk, "%.2f", temp);

                    if (colorful_output) {
                        END_COLOR;
                        colorful_output = false;
                    }

                    break;
                }
                prop_object_iterator_release(iter2);
            }
        error_netbsd3:
            prop_object_iterator_release(iter);
        error_netbsd2:
            prop_object_release(dict);
        error_netbsd1:
            close(fd);
            if (err)
                goto error;

#endif

            walk += strlen("degrees");
        }
    }

    free(thermal_zone);

    OUTPUT_FULL_TEXT(buffer);
    return;
error:
    free(thermal_zone);
#endif

    OUTPUT_FULL_TEXT("can't read temp");
    (void)fputs("i3status: Cannot read temperature. Verify that you have a thermal zone in /sys/class/thermal or disable the cpu_temperature module in your i3status config.\n", stderr);
}
コード例 #30
0
/*
 * List all available dm devices in system. 
 */	
static int
dm_list_devices(prop_dictionary_t dm_dict, struct dm_ioctl *dmi)
{
	struct dm_name_list *dml,*odml;
	
	prop_array_t targets;
	prop_dictionary_t target_dict;
	prop_object_iterator_t iter;

	uint32_t minor;
	uint32_t major;
	
	char *name;
	size_t j,slen,rec_size;

	odml = NULL;
	name = NULL;
	minor = 0;
	j = 0;

	nbsd_get_dm_major(&major,DM_BLOCK_MAJOR);
		
	dml = (struct dm_name_list *)((uint8_t *)dmi + dmi->data_start);

	if ((targets = prop_dictionary_get(dm_dict,DM_IOCTL_CMD_DATA))){

		iter = prop_array_iterator(targets);
		if (!iter)
			err(EXIT_FAILURE,"dm_list_devices %s",__func__);

		while((target_dict = prop_object_iterator_next(iter)) != NULL){

			prop_dictionary_get_cstring_nocopy(target_dict,
			    DM_DEV_NAME,(const char **)&name);

			prop_dictionary_get_uint32(target_dict,DM_DEV_DEV,&minor);

			dml->dev = MKDEV(major,minor);
			
			slen = strlen(name) + 1;
			rec_size = sizeof(struct dm_name_list) + slen + 1;

			if (rec_size > dmi->data_size)
				return -ENOMEM;
			
			dml->next = rec_size;
			
			strlcpy(dml->name,name,slen);
			
			odml = dml;
			
			dml =(struct dm_name_list *)((uint8_t *)dml + rec_size);

			j++;
		}

		if (odml != NULL)
			odml->next = 0;
	}
	prop_object_iterator_release(iter);
	return j;
}