Linux XFS filesystem development
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@infradead.org>
Cc: "A. Wilcox" <AWilcox@wilcox-tech.com>,
	Andrey Albershteyn <aalbersh@redhat.com>,
	linux-xfs@vger.kernel.org
Subject: Re: [PATCH] xfs_scrub: fix strerror_r usage yet again
Date: Fri, 19 Sep 2025 09:06:22 -0700	[thread overview]
Message-ID: <20250919160622.GM8096@frogsfrogsfrogs> (raw)
In-Reply-To: <aM1tAlLshkg7Hi3b@infradead.org>

On Fri, Sep 19, 2025 at 07:47:30AM -0700, Christoph Hellwig wrote:
> On Thu, Sep 18, 2025 at 12:48:36PM -0700, Darrick J. Wong wrote:
> > "Fix" this standards body own goal by casting the return value to
> > intptr_t and employing some gross heuristics to guess at the location of
> > the actual error string.
> 
> That really makes things worse.  I think we'll just want ifdefs for the
> two versions if there is no better option.

But what is there to #ifdef on?  _GNU_SOURCE is always included in
CFLAGS by builddefs.in even if we're not building against GNU libc
and doesn't define any new symbols so you can figure out which version
you got:

/* Reentrant version of `strerror'.
   There are 2 flavors of `strerror_r', GNU which returns the string
   and may or may not use the supplied temporary buffer and POSIX one
   which fills the string into the buffer.
   To use the POSIX version, -D_XOPEN_SOURCE=600 or -D_POSIX_C_SOURCE=200112L
   without -D_GNU_SOURCE is needed, otherwise the GNU version is
   preferred.  */
# if defined __USE_XOPEN2K && !defined __USE_GNU
/* Fill BUF with a string describing the meaning of the `errno' code in
   ERRNUM.  */
#  ifdef __REDIRECT_NTH
extern int __REDIRECT_NTH (strerror_r,
			   (int __errnum, char *__buf, size_t __buflen),
			   __xpg_strerror_r) __nonnull ((2))
    __attr_access ((__write_only__, 2, 3));
#  else
extern int __xpg_strerror_r (int __errnum, char *__buf, size_t __buflen)
     __THROW __nonnull ((2)) __attr_access ((__write_only__, 2, 3));
#   define strerror_r __xpg_strerror_r
#  endif
# else
/* If a temporary buffer is required, at most BUFLEN bytes of BUF will be
   used.  */
extern char *strerror_r (int __errnum, char *__buf, size_t __buflen)
     __THROW __nonnull ((2)) __wur  __attr_access ((__write_only__, 2, 3));
# endif

I tried turning off GNU_SOURCE but that broke the build even worse and I
don't feel like spending a whole lot of time fixing up all the damage
for the sake of a supporting an alt libc that I don't know how to build
against and don't much care about.

I suppose configure could detect which version you're getting, and set
its own #define that would enable us to #ifdef the callsite.  But this
"same symbol, different return types" is a whole mess of stupidity, to
say nothing of advisory feature enablement via preprocessor defines.

Anyway, v2 on its way.

--D

      reply	other threads:[~2025-09-19 16:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-18 19:48 [PATCH] xfs_scrub: fix strerror_r usage yet again Darrick J. Wong
2025-09-19 14:47 ` Christoph Hellwig
2025-09-19 16:06   ` Darrick J. Wong [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=20250919160622.GM8096@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