From: Steven Rostedt <rostedt@goodmis.org>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: David Vernet <void@manifault.com>,
linux-trace-devel@vger.kernel.org,
linux-trace-users@vger.kernel.org, kernel-team@meta.com,
julia.lawall@inria.fr, himadrispandya@gmail.com
Subject: Re: [PATCH] trace-cmd record: Reset PATH variable after strtok search
Date: Tue, 28 Nov 2023 15:28:38 -0500 [thread overview]
Message-ID: <20231128152838.5a7ed1ff@gandalf.local.home> (raw)
In-Reply-To: <7be74990-505d-44c3-9d62-5c4147778877@efficios.com>
On Tue, 28 Nov 2023 15:22:19 -0500
Mathieu Desnoyers <mathieu.desnoyers@efficios.com> wrote:
> On 2023-11-28 15:18, Steven Rostedt wrote:
> > On Tue, 28 Nov 2023 14:13:02 -0600
> > David Vernet <void@manifault.com> wrote:
>
> [...]
>
> >>> That would work too, though I don't think strtok_r() is doing anything
> >>> useful at that point. IMO it's better to either do the setenv() with
> >>> saveptr, or change that strtok_r() to a regular strtok().
> >
> > I always use strtok_r() over strtok() just because it's "safer"!
> >
> > I know it's not necessary, but the number of times I had to switch it to
> > make the code thread safe, I just decided to always use it. Just my personal
> > preference.
>
> And if you want to make your code thread-safe, you should favor working
> on a strdup() copy rather than modifying the argv or env content.
Yes, the fix was to use strdup(). It wasn't even a thread issue, nor a
library issue, as the code in question is part of the trace-cmd executable
and not the libraries. The problem was that it modified the environment
variable and then reused that same environment variable in the exec()
operation :-p
>
> Also, modifying global state prevents code from being eventually re-used
> in libraries.
That's why I now always use strtok_r() by default. It is thread (and
library) safe. I avoid using strtok() even when it's perfectly fine to do
so.
-- Steve
prev parent reply other threads:[~2023-11-28 20:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-28 19:24 [PATCH] trace-cmd record: Reset PATH variable after strtok search David Vernet
2023-11-28 19:30 ` Steven Rostedt
2023-11-28 20:08 ` David Vernet
2023-11-28 20:13 ` David Vernet
2023-11-28 20:18 ` Steven Rostedt
2023-11-28 20:22 ` Mathieu Desnoyers
2023-11-28 20:28 ` Steven Rostedt [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=20231128152838.5a7ed1ff@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=himadrispandya@gmail.com \
--cc=julia.lawall@inria.fr \
--cc=kernel-team@meta.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=linux-trace-users@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=void@manifault.com \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).