aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2006-02-01 00:32:06 +0000
committerBruce Momjian <bruce@momjian.us>2006-02-01 00:32:06 +0000
commitbc1c9adbda7b270f9441f03922cdf4f39bc24539 (patch)
treefabcb64535bf1aeeb3186369be61a79aa5faf090
parent2aa231be9ec94204856e59c7cd316b78e24da4d4 (diff)
downloadpostgresql-bc1c9adbda7b270f9441f03922cdf4f39bc24539.tar.gz
postgresql-bc1c9adbda7b270f9441f03922cdf4f39bc24539.zip
Set progname early in the postmaster/postgres binary, rather than doing
it later. This fixes a problem where EXEC_BACKEND didn't have progname set, causing a segfault if log_min_messages was set below debug2 and our own snprintf.c was being used. Also alway strdup() progname. Backpatch to 8.1.X and 8.0.X.
-rw-r--r--src/backend/main/main.c8
-rw-r--r--src/backend/postmaster/postmaster.c8
-rw-r--r--src/include/postmaster/postmaster.h3
-rw-r--r--src/port/path.c33
4 files changed, 25 insertions, 27 deletions
diff --git a/src/backend/main/main.c b/src/backend/main/main.c
index d857c42c1ed..f0209d5ab60 100644
--- a/src/backend/main/main.c
+++ b/src/backend/main/main.c
@@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/main/main.c,v 1.96.2.2 2006/01/05 00:54:50 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/main/main.c,v 1.96.2.3 2006/02/01 00:32:05 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -45,7 +45,7 @@
#include "libpq/pqsignal.h"
#endif
-
+const char *progname;
int
main(int argc, char *argv[])
@@ -77,6 +77,8 @@ main(int argc, char *argv[])
char *env_locale;
#endif
+ progname = get_progname(argv[0]);
+
/*
* On some platforms, unaligned memory accesses result in a kernel trap;
* the default kernel behavior is to emulate the memory access, but this
@@ -257,7 +259,7 @@ main(int argc, char *argv[])
* possibly first argument) we were called with. The lack of consistency
* here is historical.
*/
- if (strcmp(get_progname(argv[0]), "postmaster") == 0)
+ if (strcmp(progname, "postmaster") == 0)
{
/* Called as "postmaster" */
exit(PostmasterMain(argc, argv));
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 518aabd4bf8..f5dcdc0a8c8 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.475.2.2 2006/01/06 02:58:32 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.475.2.3 2006/02/01 00:32:05 momjian Exp $
*
* NOTES
*
@@ -171,9 +171,6 @@ char *ListenAddresses;
*/
int ReservedBackends;
-
-static const char *progname = NULL;
-
/* The socket(s) we're listening to. */
#define MAXLISTEN 64
static int ListenSocket[MAXLISTEN];
@@ -382,9 +379,6 @@ PostmasterMain(int argc, char *argv[])
char *userDoption = NULL;
int i;
- /* This will call exit() if strdup() fails. */
- progname = get_progname(argv[0]);
-
MyProcPid = PostmasterPid = getpid();
IsPostmasterEnvironment = true;
diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h
index 0ad21cf59c0..e278245d7db 100644
--- a/src/include/postmaster/postmaster.h
+++ b/src/include/postmaster/postmaster.h
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/postmaster/postmaster.h,v 1.11 2005/08/20 23:26:33 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/postmaster/postmaster.h,v 1.11.2.1 2006/02/01 00:32:06 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -34,6 +34,7 @@ extern char *bonjour_name;
extern HANDLE PostmasterHandle;
#endif
+extern const char *progname;
extern int PostmasterMain(int argc, char *argv[]);
extern void ClosePostmasterPorts(bool am_syslogger);
diff --git a/src/port/path.c b/src/port/path.c
index 8fe6d92daaf..968045cf353 100644
--- a/src/port/path.c
+++ b/src/port/path.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/port/path.c,v 1.61.2.2 2005/12/23 22:34:27 tgl Exp $
+ * $PostgreSQL: pgsql/src/port/path.c,v 1.61.2.3 2006/02/01 00:32:06 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -388,7 +388,8 @@ path_is_prefix_of_path(const char *path1, const char *path2)
const char *
get_progname(const char *argv0)
{
- const char *nodir_name;
+ const char *nodir_name;
+ const char *progname;
nodir_name = last_dir_separator(argv0);
if (nodir_name)
@@ -396,25 +397,25 @@ get_progname(const char *argv0)
else
nodir_name = skip_drive(argv0);
-#if defined(__CYGWIN__) || defined(WIN32)
- /* strip .exe suffix, regardless of case */
- if (strlen(nodir_name) > sizeof(EXE) - 1 &&
- pg_strcasecmp(nodir_name + strlen(nodir_name) - (sizeof(EXE) - 1), EXE) == 0)
+ /*
+ * Make a copy in case argv[0] is modified by ps_status.
+ * Leaks memory, but called only once.
+ */
+ progname = strdup(nodir_name);
+ if (progname == NULL)
{
- char *progname;
+ fprintf(stderr, "%s: out of memory\n", nodir_name);
+ exit(1); /* This could exit the postmaster */
+ }
- progname = strdup(nodir_name); /* leaks memory, but called only once */
- if (progname == NULL)
- {
- fprintf(stderr, "%s: out of memory\n", nodir_name);
- exit(1); /* This could exit the postmaster */
- }
+#if defined(__CYGWIN__) || defined(WIN32)
+ /* strip ".exe" suffix, regardless of case */
+ if (strlen(progname) > sizeof(EXE) - 1 &&
+ pg_strcasecmp(progname + strlen(progname) - (sizeof(EXE) - 1), EXE) == 0)
progname[strlen(progname) - (sizeof(EXE) - 1)] = '\0';
- nodir_name = progname;
- }
#endif
- return nodir_name;
+ return progname;
}