pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruce Momjian <bruce@momjian.us>
To: walther@technowledgy.de
Cc: Thomas Munro <thomas.munro@gmail.com>
Cc: Peter Eisentraut <peter@eisentraut.org>
Cc: Christophe Pettus <xof@thebuild.com>
Cc: Andrew Dunstan <andrew@dunslane.net>
Cc: PostgreSQL Bugs <pgsql-bugs@lists.postgresql.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Robert Haas <robertmhaas@gmail.com>
Subject: Re: Regression tests fail with musl libc because libpq.so can't be loaded
Date: Fri, 22 Mar 2024 15:44:28 -0400
Message-ID: <Zf3fnKpHIGpe5mOi@momjian.us> (raw)
In-Reply-To: <Zf2JU0_GDdbeBm5j@momjian.us>
References: <CA+hUKGK2cSx3dveMqBD+E9N=zJ0WawBcbk_jnPqmdWBM0DT_3Q@mail.gmail.com>
	<477fa513-6bf0-456d-8d24-1e22a19df671@technowledgy.de>
	<ZfrmN4WHuJgD95fw@momjian.us>
	<CA+hUKGJzC4rr2Yr=QZyx9W83Wv=TVJHndKF1anjNLNXVUM7TqQ@mail.gmail.com>
	<f98cd8de-1c66-491a-8409-e62c09932080@technowledgy.de>
	<36690fcf-f0c8-4d60-af49-6a7efa0e2b14@technowledgy.de>
	<CA+hUKGJAkTZUa9JGr-zsadaqsN=K0P71t-1L2t2=MQFDMc4GuQ@mail.gmail.com>
	<ZfzLsiXbguTDatiZ@momjian.us>
	<a2463df1-be45-4a76-b90f-7676d778e7b1@technowledgy.de>
	<Zf2JU0_GDdbeBm5j@momjian.us>

On Fri, Mar 22, 2024 at 09:36:19AM -0400, Bruce Momjian wrote:
> On Fri, Mar 22, 2024 at 09:33:38AM +0100, walther@technowledgy.de wrote:
> > Bruce Momjian:
> > > I suggest we use the #ifdef test to continue our existing behavior for
> > > the libraries we know about, like glibc, and use the LD_* process title
> > > truncation hack for libc's we don't recognize.
> > > 
> > > Attached is a prototype patch which implements this based on previous
> > > patches.
> > 
> > The condition to check for linux/glibc in your patch is slightly off:
> > 
> >   #if ! defined(__linux__) || (! defined(__GLIBC__) && defined(__UCLIBC__ ))
> > 
> > should be
> > 
> >   #if defined(__linux__) && ! (defined(__GLIBC__) || defined(__UCLIBC__ ))
> > 
> > With the latter, it passes tests with musl.
> 
> Yes, my logic was wrong. Not sure what I was thinking, frankly.
> 
> I am not a big fan of negating a complex conditional, but would rather
> pass the negation into the conditional, new patch attached.

With no one "hoping this patch dies in a fire"*, I have updated it with
more details, which I now think is committable to master.  Is this
something to backpatch?  Seems too rare a bug to me.

* Robert Haas, https://www.postgresql.org/message-id/CA%2BTgmoYsyrCNmg%2BYh6rgP7K8r-bYPjCeF1tPxENRFwD4VZAZvw%40mail...

-- 
  Bruce Momjian  <bruce@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

  Only you can decide what is important to you.

Attachments:

proctitle.diff (text/x-diff, 1.5K) download diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c index 5d829e6e483..b4ed2b1a365 100644 --- a/src/backend/utils/misc/ps_status.c +++ b/src/backend/utils/misc/ps_status.c @@ -151,7 +151,37 @@ save_ps_display_args(int argc, char **argv) for (i = 0; environ[i] != NULL; i++) { if (end_of_area + 1 == environ[i]) - end_of_area = environ[i] + strlen(environ[i]); + { + +#if defined(__linux__) && (! defined(__GLIBC__) && ! defined(__UCLIBC__ )) + /* + * The musl runtime linker stores pointers to variable + * values which are defined in the process's environment. + * Therefore, in these cases we cannot overwrite such + * variable values when setting the process title or dynamic + * linking (dlopen) might fail. Here, we truncate the update + * of the process title when either of two important dynamic + * linking environment variables are set. Musl does not + * define any compiler symbols, so we have to do this for + * any Linux libc we don't know is safe. + */ + if (strstr(environ[i], "LD_LIBRARY_PATH=") == environ[i] || + strstr(environ[i], "LD_PRELOAD=") == environ[i]) + { + /* + * We can overwrite the name, but stop at the equals sign. + * Future loops will not find contiguous space, but we + * don't break early because we want to count the total + * number. + */ + end_of_area = strchr(environ[i], '='); + } + else +#endif + { + end_of_area = environ[i] + strlen(environ[i]); + } + } } ps_buffer = argv[0];

view thread (86+ messages)  latest in thread

Message-ID: <Zf3fnKpHIGpe5mOi@momjian.us>
Permalink:  ../Zf3fnKpHIGpe5mOi@momjian.us/
Also on:    postgresql.org/message-id/Zf3fnKpHIGpe5mOi@momjian.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: bruce@momjian.us, walther@technowledgy.de, thomas.munro@gmail.com, peter@eisentraut.org, xof@thebuild.com, andrew@dunslane.net, pgsql-bugs@lists.postgresql.org, tgl@sss.pgh.pa.us, robertmhaas@gmail.com
  Subject: Re: Regression tests fail with musl libc because libpq.so can't be loaded
  In-Reply-To: <Zf3fnKpHIGpe5mOi@momjian.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox