mirror of
https://github.com/postgres/postgres.git
synced 2025-04-24 10:47:04 +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:
parent
c6ef3264be
commit
62a142036b
@ -13,7 +13,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.99 2006/01/05 03:01:34 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.100 2006/02/01 00:31:59 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -45,7 +45,7 @@
|
|||||||
#include "libpq/pqsignal.h"
|
#include "libpq/pqsignal.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const char *progname;
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
@ -77,6 +77,8 @@ main(int argc, char *argv[])
|
|||||||
char *env_locale;
|
char *env_locale;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
progname = get_progname(argv[0]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* On some platforms, unaligned memory accesses result in a kernel trap;
|
* On some platforms, unaligned memory accesses result in a kernel trap;
|
||||||
* the default kernel behavior is to emulate the memory access, but this
|
* 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
|
* possibly first argument) we were called with. The lack of consistency
|
||||||
* here is historical.
|
* here is historical.
|
||||||
*/
|
*/
|
||||||
if (strcmp(get_progname(argv[0]), "postmaster") == 0)
|
if (strcmp(progname, "postmaster") == 0)
|
||||||
{
|
{
|
||||||
/* Called as "postmaster" */
|
/* Called as "postmaster" */
|
||||||
exit(PostmasterMain(argc, argv));
|
exit(PostmasterMain(argc, argv));
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.479 2006/01/06 02:58:25 tgl Exp $
|
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.480 2006/02/01 00:31:59 momjian Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
*
|
*
|
||||||
@ -171,9 +171,6 @@ char *ListenAddresses;
|
|||||||
*/
|
*/
|
||||||
int ReservedBackends;
|
int ReservedBackends;
|
||||||
|
|
||||||
|
|
||||||
static const char *progname = NULL;
|
|
||||||
|
|
||||||
/* The socket(s) we're listening to. */
|
/* The socket(s) we're listening to. */
|
||||||
#define MAXLISTEN 64
|
#define MAXLISTEN 64
|
||||||
static int ListenSocket[MAXLISTEN];
|
static int ListenSocket[MAXLISTEN];
|
||||||
@ -383,9 +380,6 @@ PostmasterMain(int argc, char *argv[])
|
|||||||
char *userDoption = NULL;
|
char *userDoption = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* This will call exit() if strdup() fails. */
|
|
||||||
progname = get_progname(argv[0]);
|
|
||||||
|
|
||||||
MyProcPid = PostmasterPid = getpid();
|
MyProcPid = PostmasterPid = getpid();
|
||||||
|
|
||||||
IsPostmasterEnvironment = true;
|
IsPostmasterEnvironment = true;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* 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.12 2006/02/01 00:31:59 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -34,6 +34,7 @@ extern char *bonjour_name;
|
|||||||
extern HANDLE PostmasterHandle;
|
extern HANDLE PostmasterHandle;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern const char *progname;
|
||||||
|
|
||||||
extern int PostmasterMain(int argc, char *argv[]);
|
extern int PostmasterMain(int argc, char *argv[]);
|
||||||
extern void ClosePostmasterPorts(bool am_syslogger);
|
extern void ClosePostmasterPorts(bool am_syslogger);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 *
|
const char *
|
||||||
get_progname(const char *argv0)
|
get_progname(const char *argv0)
|
||||||
{
|
{
|
||||||
const char *nodir_name;
|
const char *nodir_name;
|
||||||
|
const char *progname;
|
||||||
|
|
||||||
nodir_name = last_dir_separator(argv0);
|
nodir_name = last_dir_separator(argv0);
|
||||||
if (nodir_name)
|
if (nodir_name)
|
||||||
@ -396,25 +397,25 @@ get_progname(const char *argv0)
|
|||||||
else
|
else
|
||||||
nodir_name = skip_drive(argv0);
|
nodir_name = skip_drive(argv0);
|
||||||
|
|
||||||
#if defined(__CYGWIN__) || defined(WIN32)
|
/*
|
||||||
/* strip .exe suffix, regardless of case */
|
* Make a copy in case argv[0] is modified by ps_status.
|
||||||
if (strlen(nodir_name) > sizeof(EXE) - 1 &&
|
* Leaks memory, but called only once.
|
||||||
pg_strcasecmp(nodir_name + strlen(nodir_name) - (sizeof(EXE) - 1), EXE) == 0)
|
*/
|
||||||
|
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 */
|
|
||||||
}
|
|
||||||
progname[strlen(progname) - (sizeof(EXE) - 1)] = '\0';
|
|
||||||
nodir_name = progname;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#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
|
#endif
|
||||||
|
|
||||||
return nodir_name;
|
return progname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user