From: Daniel Bristot de Oliveira <bristot@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-trace-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
John Kacur <jkacur@redhat.com>, Daniel Wagner <dwagner@suse.de>
Subject: Re: [PATCH 1/2] rtla: Remove procps-ng dependency
Date: Tue, 26 Apr 2022 13:57:13 +0200 [thread overview]
Message-ID: <1535620a-5a41-1ec4-3963-c9bc3b8e117f@kernel.org> (raw)
In-Reply-To: <20220425214559.55988956@gandalf.local.home>
On 4/26/22 03:45, Steven Rostedt wrote:
> On Fri, 22 Apr 2022 12:01:31 +0200
> Daniel Bristot de Oliveira <bristot@kernel.org> wrote:
>
>
>> +
>> +/*
>> + * procfs_is_workload_pid - check if a procfs entry contains a workload_prefix* comm
>> + *
>> + * Check if the procfs entry is a directory of a process, and then check if the
>> + * process has a comm with the prefix set in char *workload_prefix. As the
>> + * current users of this function only check for kernel threads, there is no
>> + * need to check for the threads for the process.
>> + *
>> + * Return: True if the proc_entry contains a comm file with workload_prefix*.
>> + * Otherwise returns false.
>> + */
>> +static int procfs_is_workload_pid(const char *workload_prefix, struct dirent *proc_entry)
>> +{
>> + char comm_path[MAX_PATH], comm[MAX_PATH];
>
> This is probably fine (but there is one issue), but I would have done this
> a little different.
>
> int len = strlen(workload_prefix);
> char comm[len + 1];
>
>> + int comm_fd, retval;
>> + char *t_name;
>> +
>> + if (proc_entry->d_type != DT_DIR)
>> + return 0;
>> +
>> + if (*proc_entry->d_name == '.')
>> + return 0;
>> +
>> + /* check if the string is a pid */
>> + for (t_name = proc_entry->d_name; t_name; t_name++) {
>> + if (!isdigit(*t_name))
>> + break;
>> + }
>> +
>> + if (*t_name != '\0')
>> + return 0;
>> +
>> + snprintf(comm_path, MAX_PATH, "/proc/%s/comm", proc_entry->d_name);
>> + comm_fd = open(comm_path, O_RDONLY);
>> + if (comm_fd < 0)
>> + return 0;
>> +
>> + memset(comm, 0, MAX_PATH);
>
> No need for the memset.
>
>> + retval = read(comm_fd, comm, MAX_PATH);
>
> retval = read(comm_fd, comm, len + 1);
>
>> +
>> + close(comm_fd);
>> +
>> + if (retval <= 0)
>> + return 0;
>
> if (comm[len] != '\n')
> return 0;
>
>> +
>> + retval = !strncmp(workload_prefix, comm, strlen(workload_prefix));
>
> What happens if strlen(workload_prefix) is greater than MAX_PATH? ;-)
That is a concern I had, but we have only two use cases on rtla so far, and they
are both bounded: 'timerlat/' 'osnoise/'...
I will add a check though.
>
> retval = !strncmp(workload_prefix, comm, len);
>
> But that's me. If you want to keep this as is, let me know.
I made these changes... but I am loosing the debug_msg() with the comm/pid that
matched. I am adding these messages (and I plan to add more) so I can use on
testing scripts...
At the same time, I can share a char buffer[MAX_PATH] for both the comm and
comm_path...
I think I will go this way (using a single buffer), adding a warning... and...
> -- Steve
>
>
>
>> + if (!retval)
>> + return 0;
also removing ! in the the revtal = !strcmp(...); if (!retval).
Thoughts?
-- Daniel
>> +
>> + /* comm already have \n */
>> + debug_msg("Found workload pid:%s comm:%s", proc_entry->d_name, comm);
>> +
>> + return 1;
>> +}
>> +
prev parent reply other threads:[~2022-04-26 11:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-22 10:01 Daniel Bristot de Oliveira
2022-04-22 10:01 ` [PATCH 2/2] rtla: Fix __set_sched_attr error message Daniel Bristot de Oliveira
2022-04-26 1:45 ` [PATCH 1/2] rtla: Remove procps-ng dependency Steven Rostedt
2022-04-26 11:57 ` Daniel Bristot de Oliveira [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1535620a-5a41-1ec4-3963-c9bc3b8e117f@kernel.org \
--to=bristot@kernel.org \
--cc=dwagner@suse.de \
--cc=jkacur@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®