From 226e9fffc855da10fcf2a69e49c52f9baf5e6e61 Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Fri, 5 Jan 2007 16:17:55 +0000 Subject: Call setrlimit if possible in pg_regress to allow core file generation, and provide a switch for similar behaviour in pg_ctl. --- src/test/regress/pg_regress.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c index 5daf28a666..236be9456d 100644 --- a/src/test/regress/pg_regress.c +++ b/src/test/regress/pg_regress.c @@ -11,7 +11,7 @@ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.23 2006/10/04 00:30:14 momjian Exp $ + * $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.24 2007/01/05 16:17:55 adunstan Exp $ * *------------------------------------------------------------------------- */ @@ -24,6 +24,11 @@ #include #include +#ifdef HAVE_SYS_RESOURCE_H +#include +#include +#endif + #include "getopt_long.h" #include "pg_config_paths.h" @@ -122,6 +127,30 @@ psql_command(const char *database, const char *query,...) the supplied arguments. */ __attribute__((format(printf, 2, 3))); +/* + * allow core files if possible. + */ +#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_CORE) +static void +unlimit_core_size(void) +{ + struct rlimit lim; + getrlimit(RLIMIT_CORE,&lim); + if (lim.rlim_max == 0) + { + fprintf(stderr, + _("%s: cannot set core size,: disallowed by hard limit.\n"), + progname); + return; + } + else if (lim.rlim_max == RLIM_INFINITY || lim.rlim_cur < lim.rlim_max) + { + lim.rlim_cur = lim.rlim_max; + setrlimit(RLIMIT_CORE,&lim); + } +} +#endif + /* * Add an item at the end of a stringlist. @@ -1459,6 +1488,10 @@ main(int argc, char *argv[]) initialize_environment(); +#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_CORE) + unlimit_core_size(); +#endif + if (temp_install) { /* -- cgit v1.2.1