mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Make get_stack_depth_rlimit() handle RLIM_INFINITY more sanely.
Rather than considering this result as meaning "unknown", report LONG_MAX. This won't change what superusers can set max_stack_depth to, but it will cause InitializeGUCOptions() to set the built-in default to 2MB not 100kB. The latter seems like a fairly unreasonable interpretation of "infinity". Per my investigation of odd buildfarm results as well as an old complaint from Heikki. Since this should persuade all the buildfarm animals to use a reasonable stack depth setting during "make check", revert previous patch that dumbed down a recursive regression test to only 5 levels.
This commit is contained in:
		@@ -19,10 +19,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "postgres.h"
 | 
					#include "postgres.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <fcntl.h>
 | 
				
			||||||
 | 
					#include <limits.h>
 | 
				
			||||||
 | 
					#include <signal.h>
 | 
				
			||||||
#include <time.h>
 | 
					#include <time.h>
 | 
				
			||||||
#include <unistd.h>
 | 
					#include <unistd.h>
 | 
				
			||||||
#include <signal.h>
 | 
					 | 
				
			||||||
#include <fcntl.h>
 | 
					 | 
				
			||||||
#include <sys/socket.h>
 | 
					#include <sys/socket.h>
 | 
				
			||||||
#ifdef HAVE_SYS_SELECT_H
 | 
					#ifdef HAVE_SYS_SELECT_H
 | 
				
			||||||
#include <sys/select.h>
 | 
					#include <sys/select.h>
 | 
				
			||||||
@@ -4107,7 +4108,7 @@ PostgresMain(int argc, char *argv[], const char *username)
 | 
				
			|||||||
/*
 | 
					/*
 | 
				
			||||||
 * Obtain platform stack depth limit (in bytes)
 | 
					 * Obtain platform stack depth limit (in bytes)
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Return -1 if unlimited or not known
 | 
					 * Return -1 if unknown
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
long
 | 
					long
 | 
				
			||||||
get_stack_depth_rlimit(void)
 | 
					get_stack_depth_rlimit(void)
 | 
				
			||||||
@@ -4123,7 +4124,10 @@ get_stack_depth_rlimit(void)
 | 
				
			|||||||
		if (getrlimit(RLIMIT_STACK, &rlim) < 0)
 | 
							if (getrlimit(RLIMIT_STACK, &rlim) < 0)
 | 
				
			||||||
			val = -1;
 | 
								val = -1;
 | 
				
			||||||
		else if (rlim.rlim_cur == RLIM_INFINITY)
 | 
							else if (rlim.rlim_cur == RLIM_INFINITY)
 | 
				
			||||||
			val = -1;
 | 
								val = LONG_MAX;
 | 
				
			||||||
 | 
							/* rlim_cur is probably of an unsigned type, so check for overflow */
 | 
				
			||||||
 | 
							else if (rlim.rlim_cur >= LONG_MAX)
 | 
				
			||||||
 | 
								val = LONG_MAX;
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			val = rlim.rlim_cur;
 | 
								val = rlim.rlim_cur;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3485,14 +3485,14 @@ InitializeGUCOptions(void)
 | 
				
			|||||||
	stack_rlimit = get_stack_depth_rlimit();
 | 
						stack_rlimit = get_stack_depth_rlimit();
 | 
				
			||||||
	if (stack_rlimit > 0)
 | 
						if (stack_rlimit > 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		int			new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
 | 
							long		new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (new_limit > 100)
 | 
							if (new_limit > 100)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			char		limbuf[16];
 | 
								char		limbuf[16];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			new_limit = Min(new_limit, 2048);
 | 
								new_limit = Min(new_limit, 2048);
 | 
				
			||||||
			sprintf(limbuf, "%d", new_limit);
 | 
								sprintf(limbuf, "%ld", new_limit);
 | 
				
			||||||
			SetConfigOption("max_stack_depth", limbuf,
 | 
								SetConfigOption("max_stack_depth", limbuf,
 | 
				
			||||||
							PGC_POSTMASTER, PGC_S_ENV_VAR);
 | 
												PGC_POSTMASTER, PGC_S_ENV_VAR);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4006,7 +4006,7 @@ $$ language plpgsql;
 | 
				
			|||||||
-- "limit" is to prevent this from being inlined
 | 
					-- "limit" is to prevent this from being inlined
 | 
				
			||||||
create function sql_recurse(float8) returns float8 as
 | 
					create function sql_recurse(float8) returns float8 as
 | 
				
			||||||
$$ select recurse($1) limit 1; $$ language sql;
 | 
					$$ select recurse($1) limit 1; $$ language sql;
 | 
				
			||||||
select recurse(5);
 | 
					select recurse(10);
 | 
				
			||||||
 recurse 
 | 
					 recurse 
 | 
				
			||||||
---------
 | 
					---------
 | 
				
			||||||
       0
 | 
					       0
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3211,7 +3211,7 @@ $$ language plpgsql;
 | 
				
			|||||||
create function sql_recurse(float8) returns float8 as
 | 
					create function sql_recurse(float8) returns float8 as
 | 
				
			||||||
$$ select recurse($1) limit 1; $$ language sql;
 | 
					$$ select recurse($1) limit 1; $$ language sql;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
select recurse(5);
 | 
					select recurse(10);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
create function error1(text) returns text language sql as
 | 
					create function error1(text) returns text language sql as
 | 
				
			||||||
$$ SELECT relname::text FROM pg_class c WHERE c.oid = $1::regclass $$;
 | 
					$$ SELECT relname::text FROM pg_class c WHERE c.oid = $1::regclass $$;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user