From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@infradead.org>
Cc: Andrey Albershteyn <aalbersh@redhat.com>,
"A. Wilcox" <AWilcox@wilcox-tech.com>,
linux-xfs@vger.kernel.org
Subject: Re: [PATCH v2] xfs_scrub: fix strerror_r usage yet again
Date: Thu, 25 Sep 2025 13:04:06 -0700 [thread overview]
Message-ID: <20250925200406.GZ8096@frogsfrogsfrogs> (raw)
In-Reply-To: <aNTuBDBU4q42J03E@infradead.org>
On Thu, Sep 25, 2025 at 12:23:48AM -0700, Christoph Hellwig wrote:
> On Tue, Sep 23, 2025 at 05:53:53PM -0700, Darrick J. Wong wrote:
> > On Mon, Sep 22, 2025 at 10:01:17AM -0700, Christoph Hellwig wrote:
> > > The autoconf maigc looks good (as good as autoconf can look anyway),
> > > but why is this code using strerror_r to start with? AFAIK on Linux
> > > strerror is using thread local storage since the damn of time, so
> > > just doing this as:
> > >
> > > fprintf(stream, _("%s."), strerror(error));
> > >
> > > should be perfectly fine, while also simpler and more portable.
> >
> > But there's no guarantee that the implementation does this, is there?
> > The manpage doesn't say anything like that.
>
> To me this pretty clear reads that the return string is stable until
> the next call to strerror as long as you only use it in the calling
> thread:
>
> "The strerror() function returns a pointer to a string that describes
> the error code passed in the argument errnum, ...
> This string must not be modified by the application, and the returned
> pointer will be invalidated on a subsequent call to strerror() or
> strerror_l(), or if the thread that obtained the string exits. No
> other library function, including perror(3), will modify this string."
Huh, I don't see "...or if the thread that obtained the string exits" in
my version of the strerror(3) manpage on Debian 12. For that matter, it
still lists strerror() as MT-Unsafe.
Looking through the manpages git repo, I see that strerror actually does
get changed to MT-Safe in commit 01576f703f820e54602:
strerror.3: Change strerror() reference from MT-Unsafe to MT-Safe
The information in this patch was obtained from a glibc upstream patch,
commit 28aff047818eb1726394296d27b9c7885340bead ("string: Implement
strerror in terms of strerror_l").
According to the patch above, for glibc versions >=2.32, strerror() is
MT-Safe.
Signed-off-by: Shani Leviim <sleviim@redhat.com>
Then looking through the glibc repository, that 28aff047818e commit
comes from:
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=28aff047818eb1726394296d27b9c7885340bead;hp=9deec7c8bab24659e78172dd850f4ca37c57940c
which turns strerror into strerror_l. This commit only appears in glibc
2.32, which appeared in August 2020. That version first appears in
Debian 12 and RHEL 9, which are still fairly new. musl apparently has
had strerror call strerror_l since at least 2011.
Has strerror() been designated as thread-safe at a POSIX level, or is
this just an implementation quirk of these two C libraries? strerror
definitely wasn't thread-safe on glibc when I wrote this program.
--D
next prev parent reply other threads:[~2025-09-25 20:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-19 16:14 [PATCH v2] xfs_scrub: fix strerror_r usage yet again Darrick J. Wong
2025-09-20 11:21 ` A. Wilcox
2025-09-22 17:01 ` Christoph Hellwig
2025-09-24 0:53 ` Darrick J. Wong
2025-09-25 7:23 ` Christoph Hellwig
2025-09-25 20:04 ` Darrick J. Wong [this message]
2025-09-25 20:58 ` Holger Hoffstätte
2025-09-26 16:27 ` Darrick J. Wong
2025-10-03 10:07 ` Andrey Albershteyn
2025-09-29 6:34 ` Christoph Hellwig
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=20250925200406.GZ8096@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=AWilcox@wilcox-tech.com \
--cc=aalbersh@redhat.com \
--cc=hch@infradead.org \
--cc=linux-xfs@vger.kernel.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