Example #1
0
int find_type_by_properties(char name[FBNAMSIZ],
			    int needed[MAX_PROPS],
			    size_t *num)
{
	size_t sat, sat_max = 0;
	int idx_max = -1, i, j, l, ret;

	if (*num <= 0)
		return -64;

	mutexlock_lock(&lock);
	for (i = 0; i < elems; ++i) {
		sat = 0;
		for (j = 0; j < MAX_PROPS; ++j) {
			if (table[i].props[j] == 0)
				continue;
			for (l = 0; l < MAX_PROPS; ++l) {
				if (needed[l] == 0)
					continue;
				if (needed[l] == table[i].props[j]) {
					sat++;
					if (sat > sat_max) {
						sat_max = sat;
						idx_max = i;
					}
				}
			}
		}
	}

	if (idx_max < 0) {
		mutexlock_unlock(&lock);
		return -64;
	}

	for (j = 0; j < MAX_PROPS; ++j) {
		if (table[idx_max].props[j] == 0)
			continue;
		for (l = 0; l < MAX_PROPS; ++l) {
			if (needed[l] == table[idx_max].props[j]) {
				needed[l] = 0;
				(*num)--;
			}
		}
	}

	strlcpy(name, table[idx_max].name, sizeof(table[idx_max].name));
	ret = table[idx_max].prio;

	mutexlock_unlock(&lock);

	return ret;
}
Example #2
0
int call_notifier_exec(unsigned long event, const void *arg)
{
	int ret;

	mutexlock_lock(&call_notifier.lock);
	ret = call_event_hooks(&call_notifier.head, event, arg, NULL);
	mutexlock_unlock(&call_notifier.lock);

	return ret;
}
Example #3
0
int unregister_call_notifier(struct event_block *block)
{
	int ret;

	mutexlock_lock(&call_notifier.lock);
	ret = unregister_event_hook(&call_notifier.head, block);
	mutexlock_unlock(&call_notifier.lock);

	return ret;
}
Example #4
0
int fbtype_is_available(char name[FBNAMSIZ])
{
	int available = 0, i;

	mutexlock_lock(&lock);
	for (i = 0; i < elems; ++i) {
		if (!strncmp(table[i].name, name, sizeof(table[i].name))) {
			available = 1;
			break;
		}
	}
	mutexlock_unlock(&lock);

	return available;
}
Example #5
0
static void *property_fetcher(void *null)
{
	int first = 1, i, stop;
	FILE *fp;
	char buff[1024], *ptr, *nptr;
	char type[128];

	mutexlock_init(&lock);

	while (!sigint) {
		/* FIXME: HACK: extremly lame, do it better later on */

		mutexlock_lock(&lock);

		memset(table, 0, sizeof(table));
		elems = 0;
		first = 1;

		fp = fopen("/proc/net/lana/properties", "r");
		if (!fp)
			panic("LANA not running?\n");

		memset(buff, 0, sizeof(buff));
		while (fgets(buff, sizeof(buff), fp) != NULL) {
			buff[sizeof(buff) - 1] = 0;
			if (first) {
				first = 0;
				continue;
			}

			if (elems + 1 >= MAX_ELEMS)
				panic("Too many fblock instances!\n");

			memset(type, 0, sizeof(type));
			if (sscanf(buff, "%s [", type) != 1)
				continue;

			strlcpy(table[elems].name, type, sizeof(table[elems].name));

			i = stop = 0;
			ptr = strstr(buff, "[");
			ptr++;
			//XXX
			// prop_str_tab_put_idx(char*)
//			while (!stop && (j = strtoul(ptr, &nptr, 10))) {
			while (!stop) {
				nptr = ptr;
				while (*nptr != ' ' && *nptr != ']') {
					nptr++;
				}
				if (*nptr == ' ' || *nptr == ']') {
					int tmp;
					char foo;
					foo = *nptr;
					*nptr = '\0';
					table[elems].props[i++] = tmp = prop_str_tab_put_idx(ptr);
					ptr = nptr + 1;
					*nptr = foo;
				}
				if (*nptr == ']') {
					stop = 1;
					continue;
				}

//				if (!nptr)
//					break;
//				if (i + 1 >= MAX_PROPS)
//					panic("Too many properties!\n");
//				table[elems].props[i++] = j;
//				if (*nptr == ']')
//					stop = 1;
//				nptr++;
//				ptr = nptr;
			}

			table[elems].prio = strtol(ptr, &nptr, 10);
			memset(buff, 0, sizeof(buff));
			elems++;
		}

		fclose(fp);

		mutexlock_unlock(&lock);
		sleep(10);
	}

	mutexlock_destroy(&lock);
	pthread_exit(NULL);
}