Index: src/bin/pg_ctl/pg_ctl.c =================================================================== RCS file: /cvsroot/pgsql/src/bin/pg_ctl/pg_ctl.c,v retrieving revision 1.74 diff -c -r1.74 pg_ctl.c *** src/bin/pg_ctl/pg_ctl.c 12 Oct 2006 05:14:49 -0000 1.74 --- src/bin/pg_ctl/pg_ctl.c 29 Dec 2006 21:08:39 -0000 *************** *** 26,31 **** --- 26,36 ---- #include #include + #ifdef HAVE_SYS_RESOURCE_H + #include + #include + #endif + #include "libpq/pqsignal.h" #include "getopt_long.h" *************** *** 90,95 **** --- 95,103 ---- static char *register_username = NULL; static char *register_password = NULL; static char *argv0 = NULL; + #if HAVE_GETRLIMIT + static bool allow_core_files = false; + #endif static void write_stderr(const char *fmt,...) *************** *** 132,137 **** --- 140,149 ---- static char pid_file[MAXPGPATH]; static char conf_file[MAXPGPATH]; + #if HAVE_GETRLIMIT + static void unlimit_core_size(void); + #endif + #if defined(WIN32) || defined(__CYGWIN__) static void *************** *** 478,483 **** --- 490,516 ---- } + #if HAVE_GETRLIMIT + static void + unlimit_core_size(void) + { + struct rlimit lim; + getrlimit(RLIMIT_CORE,&lim); + if (lim.rlim_max == 0) + { + write_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 + + static void do_start(void) *************** *** 581,586 **** --- 614,624 ---- postgres_path = postmaster_path; } + #if HAVE_GETRLIMIT + if (allow_core_files) + unlimit_core_size(); + #endif + exitcode = start_postmaster(); if (exitcode != 0) { *************** *** 1401,1406 **** --- 1439,1447 ---- printf(_(" -o OPTIONS command line options to pass to postgres\n" " (PostgreSQL server executable)\n")); printf(_(" -p PATH-TO-POSTGRES normally not necessary\n")); + #if HAVE_GETRLIMIT + printf(_(" -c, --corefiles allow postgres to produce core files\n")); + #endif printf(_("\nOptions for stop or restart:\n")); printf(_(" -m SHUTDOWN-MODE may be \"smart\", \"fast\", or \"immediate\"\n")); *************** *** 1497,1502 **** --- 1538,1546 ---- {"mode", required_argument, NULL, 'm'}, {"pgdata", required_argument, NULL, 'D'}, {"silent", no_argument, NULL, 's'}, + #if HAVE_GETRLIMIT + {"corefiles", no_argument, NULL, 'c'}, + #endif {NULL, 0, NULL, 0} }; *************** *** 1561,1567 **** /* process command-line options */ while (optind < argc) { ! while ((c = getopt_long(argc, argv, "D:l:m:N:o:p:P:sU:wW", long_options, &option_index)) != -1) { switch (c) { --- 1605,1611 ---- /* process command-line options */ while (optind < argc) { ! while ((c = getopt_long(argc, argv, "cD:l:m:N:o:p:P:sU:wW", long_options, &option_index)) != -1) { switch (c) { *************** *** 1632,1637 **** --- 1676,1686 ---- do_wait = false; wait_set = true; break; + #if HAVE_GETRLIMIT + case 'c': + allow_core_files = true; + break; + #endif default: /* getopt_long already issued a suitable error message */ do_advice();