예제 #1
0
파일: util.c 프로젝트: DenisLug/mptcp
bool find_process(const char *name)
{
	size_t len = strlen(name);
	DIR *dir;
	struct dirent *d;
	int ret = -1;

	dir = opendir(procfs__mountpoint());
	if (!dir)
		return false;

	/* Walk through the directory. */
	while (ret && (d = readdir(dir)) != NULL) {
		char path[PATH_MAX];
		char *data;
		size_t size;

		if ((d->d_type != DT_DIR) ||
		     !strcmp(".", d->d_name) ||
		     !strcmp("..", d->d_name))
			continue;

		scnprintf(path, sizeof(path), "%s/%s/comm",
			  procfs__mountpoint(), d->d_name);

		if (filename__read_str(path, &data, &size))
			continue;

		ret = strncmp(name, data, len);
		free(data);
	}

	closedir(dir);
	return ret ? false : true;
}
예제 #2
0
파일: util.c 프로젝트: daveti/tcpSockHack
int perf_event_paranoid(void)
{
	char path[PATH_MAX];
	const char *procfs = procfs__mountpoint();
	int value;

	if (!procfs)
		return INT_MAX;

	scnprintf(path, PATH_MAX, "%s/sys/kernel/perf_event_paranoid", procfs);

	if (filename__read_int(path, &value))
		return INT_MAX;

	return value;
}
예제 #3
0
파일: thread_map.c 프로젝트: AK101111/linux
static int get_comm(char **comm, pid_t pid)
{
	char *path;
	size_t size;
	int err;

	if (asprintf(&path, "%s/%d/comm", procfs__mountpoint(), pid) == -1)
		return -ENOMEM;

	err = filename__read_str(path, comm, &size);
	if (!err) {
		/*
		 * We're reading 16 bytes, while filename__read_str
		 * allocates data per BUFSIZ bytes, so we can safely
		 * mark the end of the string.
		 */
		(*comm)[size] = 0;
		rtrim(*comm);
	}

	free(path);
	return err;
}