Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit62a1420

Browse files
committed
Set progname early in the postmaster/postgres binary, rather than doing
it later. This fixes a problem where EXEC_BACKEND didn't have prognameset, causing a segfault if log_min_messages was set below debug2 and ourown snprintf.c was being used.Also alway strdup() progname.Backpatch to 8.1.X and 8.0.X.
1 parentc6ef326 commit62a1420

File tree

4 files changed

+25
-27
lines changed

4 files changed

+25
-27
lines changed

‎src/backend/main/main.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.99 2006/01/05 03:01:34 momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.100 2006/02/01 00:31:59 momjian Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -45,7 +45,7 @@
4545
#include"libpq/pqsignal.h"
4646
#endif
4747

48-
48+
constchar*progname;
4949

5050
int
5151
main(intargc,char*argv[])
@@ -77,6 +77,8 @@ main(int argc, char *argv[])
7777
char*env_locale;
7878
#endif
7979

80+
progname=get_progname(argv[0]);
81+
8082
/*
8183
* On some platforms, unaligned memory accesses result in a kernel trap;
8284
* the default kernel behavior is to emulate the memory access, but this
@@ -246,7 +248,7 @@ main(int argc, char *argv[])
246248
* possibly first argument) we were called with. The lack of consistency
247249
* here is historical.
248250
*/
249-
if (strcmp(get_progname(argv[0]),"postmaster")==0)
251+
if (strcmp(progname,"postmaster")==0)
250252
{
251253
/* Called as "postmaster" */
252254
exit(PostmasterMain(argc,argv));

‎src/backend/postmaster/postmaster.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.479 2006/01/06 02:58:25 tgl Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.480 2006/02/01 00:31:59 momjian Exp $
4141
*
4242
* NOTES
4343
*
@@ -171,9 +171,6 @@ char *ListenAddresses;
171171
*/
172172
intReservedBackends;
173173

174-
175-
staticconstchar*progname=NULL;
176-
177174
/* The socket(s) we're listening to. */
178175
#defineMAXLISTEN64
179176
staticintListenSocket[MAXLISTEN];
@@ -383,9 +380,6 @@ PostmasterMain(int argc, char *argv[])
383380
char*userDoption=NULL;
384381
inti;
385382

386-
/* This will call exit() if strdup() fails. */
387-
progname=get_progname(argv[0]);
388-
389383
MyProcPid=PostmasterPid=getpid();
390384

391385
IsPostmasterEnvironment= true;

‎src/include/postmaster/postmaster.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/postmaster/postmaster.h,v 1.11 2005/08/20 23:26:33 tgl Exp $
9+
* $PostgreSQL: pgsql/src/include/postmaster/postmaster.h,v 1.12 2006/02/01 00:31:59 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -34,6 +34,7 @@ extern char *bonjour_name;
3434
externHANDLEPostmasterHandle;
3535
#endif
3636

37+
externconstchar*progname;
3738

3839
externintPostmasterMain(intargc,char*argv[]);
3940
externvoidClosePostmasterPorts(boolam_syslogger);

‎src/port/path.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/port/path.c,v 1.63 2005/12/23 22:34:22 tgl Exp $
11+
* $PostgreSQL: pgsql/src/port/path.c,v 1.64 2006/02/01 00:31:59 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -388,33 +388,34 @@ path_is_prefix_of_path(const char *path1, const char *path2)
388388
constchar*
389389
get_progname(constchar*argv0)
390390
{
391-
constchar*nodir_name;
391+
constchar*nodir_name;
392+
constchar*progname;
392393

393394
nodir_name=last_dir_separator(argv0);
394395
if (nodir_name)
395396
nodir_name++;
396397
else
397398
nodir_name=skip_drive(argv0);
398399

399-
#if defined(__CYGWIN__)|| defined(WIN32)
400-
/* strip .exe suffix, regardless of case */
401-
if (strlen(nodir_name)>sizeof(EXE)-1&&
402-
pg_strcasecmp(nodir_name+strlen(nodir_name)- (sizeof(EXE)-1),EXE)==0)
400+
/*
401+
*Make a copy in case argv[0] is modified by ps_status.
402+
*Leaks memory, but called only once.
403+
*/
404+
progname=strdup(nodir_name);
405+
if (progname==NULL)
403406
{
404-
char*progname;
407+
fprintf(stderr,"%s: out of memory\n",nodir_name);
408+
exit(1);/* This could exit the postmaster */
409+
}
405410

406-
progname=strdup(nodir_name);/* leaks memory, but called only once */
407-
if (progname==NULL)
408-
{
409-
fprintf(stderr,"%s: out of memory\n",nodir_name);
410-
exit(1);/* This could exit the postmaster */
411-
}
411+
#if defined(__CYGWIN__)|| defined(WIN32)
412+
/* strip ".exe" suffix, regardless of case */
413+
if (strlen(progname)>sizeof(EXE)-1&&
414+
pg_strcasecmp(progname+strlen(progname)- (sizeof(EXE)-1),EXE)==0)
412415
progname[strlen(progname)- (sizeof(EXE)-1)]='\0';
413-
nodir_name=progname;
414-
}
415416
#endif
416417

417-
returnnodir_name;
418+
returnprogname;
418419
}
419420

420421

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp