aboutsummaryrefslogtreecommitdiff
path: root/src/port/path.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2006-02-01 00:31:59 +0000
committerBruce Momjian <bruce@momjian.us>2006-02-01 00:31:59 +0000
commit62a142036ba59c8167ab4539a414e56ba4c39faa (patch)
tree5c0ebf00e2e9a5569db8ea3a1985224fe7f796d0 /src/port/path.c
parentc6ef3264bebd442ae19a850abd774ed4bde1722f (diff)
downloadpostgresql-62a142036ba59c8167ab4539a414e56ba4c39faa.tar.gz
postgresql-62a142036ba59c8167ab4539a414e56ba4c39faa.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.
Diffstat (limited to 'src/port/path.c')
-rw-r--r--src/port/path.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/port/path.c b/src/port/path.c
index 463c50f7287..ba7fd9d712d 100644
--- a/src/port/path.c
+++ b/src/port/path.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/port/path.c,v 1.63 2005/12/23 22:34:22 tgl Exp $
+ * $PostgreSQL: pgsql/src/port/path.c,v 1.64 2006/02/01 00:31:59 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;
}