mirror of
https://github.com/postgres/postgres.git
synced 2025-08-18 12:22:09 +03:00
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.
This commit is contained in:
@@ -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;
|
||||
|
||||
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 */
|
||||
}
|
||||
progname[strlen(progname) - (sizeof(EXE) - 1)] = '\0';
|
||||
nodir_name = progname;
|
||||
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';
|
||||
#endif
|
||||
|
||||
return nodir_name;
|
||||
return progname;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user