Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnkof-00EwJn-RG for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Mar 2024 19:44:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rnkod-0076XD-Un for pgsql-bugs@arkaria.postgresql.org; Fri, 22 Mar 2024 19:44:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnkod-0076X5-Md for pgsql-bugs@lists.postgresql.org; Fri, 22 Mar 2024 19:44:36 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnkoa-005uJs-CF for pgsql-bugs@lists.postgresql.org; Fri, 22 Mar 2024 19:44:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2024011501; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description; bh=NHi3yh9BPhrndApSHP/OShCfhJKodslkcpnAJr/9BqM=; b=RmQWH 0D0oUCUlwcg294GhqumlRuUdDftVJRBPbETWayCV/qcXpZZUdFhP13uXEbVicDxmZpgKr23oBSWcc geKzlHNhcDnJIzDu1qUgZLP9Gj3RY2OeJJT34LTp9CQfgxFYVwSY2kCvTJ0hy25FSLare6zm4Sbuj sto2ey6yabUGJuFTakh6376P0TwSHdQKQj8MvE3at7Sg69UByi/CIx05qglzkvqVdOX2i507AK6jP ZFIHyEzV/BAn1WVW+nnHY6VlmwMSiStZTjoJ9/AcgpEPHbKAuMlaZcoYcNr9wlWQ3c0xJVa9Hz/ep LU06fkkqZWsC4jpmG/sT07lEquKVQ==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1rnkoW-007SIy-2G; Fri, 22 Mar 2024 15:44:28 -0400 Date: Fri, 22 Mar 2024 15:44:28 -0400 From: Bruce Momjian To: walther@technowledgy.de Cc: Thomas Munro , Peter Eisentraut , Christophe Pettus , Andrew Dunstan , PostgreSQL Bugs , Tom Lane , Robert Haas Subject: Re: Regression tests fail with musl libc because libpq.so can't be loaded Message-ID: References: <477fa513-6bf0-456d-8d24-1e22a19df671@technowledgy.de> <36690fcf-f0c8-4d60-af49-6a7efa0e2b14@technowledgy.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="bGF/Zmuer4T+L7xb" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --bGF/Zmuer4T+L7xb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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.gmail.com -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Only you can decide what is important to you. --bGF/Zmuer4T+L7xb Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="proctitle.diff" 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]; --bGF/Zmuer4T+L7xb--