Exemple #1
0
void lib_watch_event(struct inotify_event *e, const char *path, void *payload)
	{
	lib_entry entry;
	lib_t *lib=(lib_t*)payload;
	size_t l=strlen(path)+strlen(e->name)+1;
	char *f=malloc(l+1);
	strcpy(f, path);
	strcat(f, e->name);
	debug(ll, "watch_even '%s%s'", path, e->name);
	if(e->mask&IN_CLOSE_WRITE || e->mask&IN_CREATE || e->mask&IN_MOVED_TO)
		{
		struct stat buf;
		stat(f, &buf);
		if(S_ISDIR(buf.st_mode))
			{
			f[l-1]='/';
			f[l]=0;
			parse_dir(lib, &f, l, &entry);
			}
		else
			parse_file(lib, f, &entry);
		}
	else if(e->mask&IN_DELETE || e->mask&IN_DELETE_SELF || e->mask&IN_MOVED_FROM)
		{
		iterator_t *it=chunked_list_iterator(lib->entries);
		while(iterator_has_next(it))
			{
			lib_entry *e=iterator_next(it);
			if(strncmp(f, e->path, l-1)==0)
				iterator_remove(it);
			}
		}
	}
Exemple #2
0
static void request_game_list(const char *s) {
	game_t *g;

	struct iterator it = list_iterator(&public_games);
	while ((g = iterator_next(&it))) {
		g->active = FALSE;
	}

	struct timespec ts;
	clock_gettime(CLOCK_REALTIME, &ts);
	ts.tv_sec += 2;

	pthread_mutex_lock(&pub_m);

	mcp_send(0x05, "%w 00 00 00 00 %s 00", request_id, s);
	request_id++;

	pthread_cond_timedwait(&pub_cv, &pub_m, &ts);

	it = list_iterator(&public_games);
	while ((g = iterator_next(&it))) {
		if (!g->active) {
			iterator_remove(&it);
			plugin_debug("mcp game", "removing inactive game\n");
		}
	}

	dump_game_list(&public_games);

	pthread_mutex_unlock(&pub_m);
}
Exemple #3
0
void *check_lib(void *arg)
	{
	size_t l;
	char *n;
	lib_entry *entry;
	lib_t *lib=(lib_t *)arg;
	iterator_t *it=chunked_list_iterator(lib->entries);
	info(ll, "starting checker");
	while(iterator_has_next(it))
		{
		lib_entry *e=iterator_next(it);
		char *f=lib_canonize(lib, e->path);
		debug(ll, "cheking '%s'", f);
		if(access(f, R_OK))
			iterator_remove(it);
		free(f);
		}

	l=lib->base_path_size+1;
	n=malloc(l);
	memcpy(n, lib->base_path, l);

	entry=malloc(sizeof(lib_entry));

	parse_dir(lib, &n, l, entry);
	free(n);
	free(entry);
	}