On 5/10/22 13:30, Daniel Wagner wrote: > On Tue, May 10, 2022 at 11:57:04AM +0200, Daniel Bristot de Oliveira wrote: >> -int set_comm_sched_attr(const char *comm, struct sched_attr *attr) >> +int set_comm_sched_attr(const char *comm_prefix, struct sched_attr *attr) >> { >> - int flags = PROC_FILLCOM | PROC_FILLSTAT; >> - PROCTAB *ptp; >> - proc_t task; >> + struct dirent *proc_entry; >> + DIR *procfs; >> int retval; >> >> - ptp = openproc(flags); >> - if (!ptp) { >> - err_msg("error openproc()\n"); >> - return -ENOENT; >> + if (strlen(comm_prefix) >= MAX_PATH) { >> + err_msg("Command prefix is too long: %d < strlen(%s)\n", >> + MAX_PATH, comm_prefix); >> + exit(EINVAL); >> } >> >> - memset(&task, 0, sizeof(task)); >> + procfs = opendir("/proc"); > > Maybe you want to check if procfs is a valid handle before using it. Yes I want! >> + >> + while ((proc_entry = readdir(procfs))) { >> >> - while (readproc(ptp, &task)) { >> - retval = strncmp(comm, task.cmd, strlen(comm)); >> - if (retval) >> + retval = procfs_is_workload_pid(comm_prefix, proc_entry); >> + if (!retval) >> continue; >> - retval = __set_sched_attr(task.tid, attr); >> - if (retval) >> + >> + /* procfs_is_workload_pid confirmed it is a pid */ >> + retval = __set_sched_attr(atoi(proc_entry->d_name), attr); >> + if (retval) { >> + err_msg("Error setting sched attributes for pid:%s\n", proc_entry->d_name); >> goto out_err; >> - } >> + } >> >> - closeproc(ptp); >> + debug_msg("Set sched attributes for pid:%s\n", proc_entry->d_name); >> + } >> return 0; >> >> out_err: >> - closeproc(ptp); >> + closedir(procfs); >> return 1; >> } >> >> diff --git a/tools/tracing/rtla/src/utils.h b/tools/tracing/rtla/src/utils.h >> index fa08e374870a..5571afd3b549 100644 >> --- a/tools/tracing/rtla/src/utils.h >> +++ b/tools/tracing/rtla/src/utils.h >> @@ -6,6 +6,7 @@ >> * '18446744073709551615\0' >> */ >> #define BUFF_U64_STR_SIZE 24 >> +#define MAX_PATH 1024 > > linux/limits.h defined MAX_PATH as well, though as 4096. Maybe use that > definition? If you want to make it dynamic you could use fpathconf(fd, > _PC_PATH_MAX) but one could argue that is over engineering :) > > Thanks for the fix. Anyway just nitpicking. Fedora did not find it by default... let's just define our own here. > Reviewed-by: Daniel Wagner <dwagner@xxxxxxx> Thanks! -- Daniel