Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd82605b

Browse files
committed
Allow "make check"-style testing to work with musl C library.
The musl dynamic linker saves a pointer to the process' environmentvalue of LD_LIBRARY_PATH very early in startup. When we move/clobberthe environment to make more room for ps status strings, we clobberthat value and thereby prevent libraries from being found viaLD_LIBRARY_PATH, which breaks the use of a temporary installationfor testing purposes. To fix, stop collecting usable space forps status if we notice that the variable we are about to clobberis LD_LIBRARY_PATH. This will result in some reduction in how longthe ps status can be, but it's only likely to occur in temporarytest contexts, so it doesn't seem like a big problem. In any case,we don't have to do it if we see we are on glibc, which surely iswhere the majority of our Linux testing is done.Thomas Munro, Bruce Momjian, and Tom Lane, per report from WolfgangWalther. Back-patch to all supported branches, with the hope thatwe'll set up a buildfarm animal to test on this platform.Discussion:https://postgr.es/m/fddd1cd6-dc16-40a2-9eb5-d7fef2101488@technowledgy.de
1 parent24d1b99 commitd82605b

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

‎src/backend/utils/misc/ps_status.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ static char **save_argv;
122122
* (The original argv[] will not be overwritten by this routine, but may be
123123
* overwritten during init_ps_display. Also, the physical location of the
124124
* environment strings may be moved, so this should be called before any code
125-
* that might try to hang onto a getenv() result.)
125+
* that might try to hang onto a getenv() result. But see hack for musl
126+
* within.)
126127
*
127128
* Note that in case of failure this cannot call elog() as that is not
128129
* initialized yet. We rely on write_stderr() instead.
@@ -137,7 +138,7 @@ save_ps_display_args(int argc, char **argv)
137138

138139
/*
139140
* If we're going to overwrite the argv area, count the available space.
140-
* Also move the environment to make additional room.
141+
* Also move the environmentstringsto make additional room.
141142
*/
142143
{
143144
char*end_of_area=NULL;
@@ -166,7 +167,33 @@ save_ps_display_args(int argc, char **argv)
166167
for (i=0;environ[i]!=NULL;i++)
167168
{
168169
if (end_of_area+1==environ[i])
169-
end_of_area=environ[i]+strlen(environ[i]);
170+
{
171+
/*
172+
* The musl dynamic linker keeps a static pointer to the
173+
* initial value of LD_LIBRARY_PATH, if that is defined in the
174+
* process's environment. Therefore, we must not overwrite the
175+
* value of that setting and thus cannot advance end_of_area
176+
* beyond it. Musl does not define any identifying compiler
177+
* symbol, so we have to do this unless we see a symbol
178+
* identifying a Linux libc we know is safe.
179+
*/
180+
#if defined(__linux__)&& (!defined(__GLIBC__)&& !defined(__UCLIBC__))
181+
if (strncmp(environ[i],"LD_LIBRARY_PATH=",16)==0)
182+
{
183+
/*
184+
* We can overwrite the name, but stop at the equals sign.
185+
* Future loop iterations will not find any more
186+
* contiguous space, but we don't break early because we
187+
* need to count the total number of environ[] entries.
188+
*/
189+
end_of_area=environ[i]+15;
190+
}
191+
else
192+
#endif
193+
{
194+
end_of_area=environ[i]+strlen(environ[i]);
195+
}
196+
}
170197
}
171198

172199
ps_buffer=argv[0];
@@ -201,7 +228,7 @@ save_ps_display_args(int argc, char **argv)
201228
* If we're going to change the original argv[] then make a copy for
202229
* argument parsing purposes.
203230
*
204-
*(NB: do NOT think to remove the copying of argv[], even though
231+
* NB: do NOT think to remove the copying of argv[], even though
205232
* postmaster.c finishes looking at argv[] long before we ever consider
206233
* changing the ps display. On some platforms, getopt() keeps pointers
207234
* into the argv array, and will get horribly confused when it is

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp