Re: [PATCH] trace-cmd record: Reset PATH variable after strtok search

Mathieu Desnoyers <[email protected]> Tue, 28 Nov 2023 15:22:19 -0500
Newsgroups org.kernel.vger.linux-trace-users,org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
On 2023-11-28 15:18, Steven Rostedt wrote:
> On Tue, 28 Nov 2023 14:13:02 -0600
> David Vernet <[email protected]> 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.

Also, modifying global state prevents code from being eventually re-used 
in libraries.

Thanks,

Mathieu

> 
> -- Steve
> 
> 
>>>    
>>>>
>>>> Although, I still need to test the result of strdup().
>>>>
>>>> -- Steve
> 
> 

-- 
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com