summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian2006-02-01 00:47:03 +0000
committerBruce Momjian2006-02-01 00:47:03 +0000
commit46926f17aae01a40c853c6b1342e75bf6bda6e99 (patch)
tree6afdf058e860b72f8e9b2699d14463b0a286391d
parent2355244202273548f42f71513abef3ccefbd6369 (diff)
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.c6
-rw-r--r--src/backend/postmaster/postmaster.c6
-rw-r--r--src/include/postmaster/postmaster.h1
-rw-r--r--src/port/path.c31
4 files changed, 21 insertions, 23 deletions
diff --git a/src/backend/main/main.c b/src/backend/main/main.c
index db46eb12e8..efbd25a1fa 100644
--- a/src/backend/main/main.c
+++ b/src/backend/main/main.c
@@ -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
@@ -246,7 +248,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 c24a6bb329..b580851dfd 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -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];
@@ -383,9 +380,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 38b59e4a2d..27f0bd0a4c 100644
--- a/src/include/postmaster/postmaster.h
+++ b/src/include/postmaster/postmaster.h
@@ -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 2a1853f540..79917629b6 100644
--- a/src/port/path.c
+++ b/src/port/path.c
@@ -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;
}