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; }
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; }
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; }