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:
Bruce Momjian 2006-02-01 00:47:03 +00:00
parent 2426c62140
commit 5eb493ab98
4 changed files with 26 additions and 28 deletions

View File

@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.94.4.1 2006/01/05 00:55:07 tgl Exp $
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.94.4.2 2006/02/01 00:47:02 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -45,7 +45,7 @@
#include "libpq/pqsignal.h"
#endif
const char *progname;
int
main(int argc, char *argv[])
@ -101,6 +101,8 @@ main(int argc, char *argv[])
#endif
#endif /* NOFIXADE */
progname = get_progname(argv[0]);
#if defined(WIN32)
{
WSADATA wsaData;

View File

@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.443.4.5 2006/01/06 02:58:40 tgl Exp $
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.443.4.6 2006/02/01 00:47:02 momjian Exp $
*
* NOTES
*
@ -168,9 +168,6 @@ char *ListenAddresses;
*/
int ReservedBackends;
static const char *progname = NULL;
/* The socket(s) we're listening to. */
#define MAXLISTEN 64
static int ListenSocket[MAXLISTEN];
@ -375,9 +372,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;

View File

@ -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.9 2004/12/31 22:03:39 pgsql Exp $
* $PostgreSQL: pgsql/src/include/postmaster/postmaster.h,v 1.9.4.1 2006/02/01 00:47:03 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -34,6 +34,7 @@ extern char *rendezvous_name;
extern HANDLE PostmasterHandle;
#endif
extern const char *progname;
extern int PostmasterMain(int argc, char *argv[]);
extern void ClosePostmasterPorts(bool am_syslogger);

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/port/path.c,v 1.50.4.2 2005/12/23 22:34:33 tgl Exp $
* $PostgreSQL: pgsql/src/port/path.c,v 1.50.4.3 2006/02/01 00:47:03 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -302,7 +302,8 @@ canonicalize_path(char *path)
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)
@ -310,27 +311,27 @@ 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);
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;
}
/*
* dir_strcmp: strcmp except any two DIR_SEP characters are considered equal