diff options
| author | Tom Lane | 2001-10-21 03:25:36 +0000 |
|---|---|---|
| committer | Tom Lane | 2001-10-21 03:25:36 +0000 |
| commit | b2e92a712ea7316563c5115639c1e39ad6c5a09b (patch) | |
| tree | 6f2a91acddea6238d72599745faa976eff947486 /src/backend/postmaster | |
| parent | 2b7206a9935c915155a2c71e4658638de98ad440 (diff) | |
Fix getopt-vs-init_ps_display problem by copying original argv[] info,
per suggestion from Peter. Simplify several APIs by transmitting the
original argv location directly from main.c to ps_status.c, instead of
passing it down through several levels of subroutines.
Diffstat (limited to 'src/backend/postmaster')
| -rw-r--r-- | src/backend/postmaster/pgstat.c | 23 | ||||
| -rw-r--r-- | src/backend/postmaster/postmaster.c | 65 |
2 files changed, 39 insertions, 49 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index c7e83fe9da4..44ce0b750f6 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -16,7 +16,7 @@ * * Copyright (c) 2001, PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.11 2001/10/16 22:35:27 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.12 2001/10/21 03:25:35 tgl Exp $ * ---------- */ #include "postgres.h" @@ -95,8 +95,8 @@ static char pgStat_fname[MAXPGPATH]; * Local function forward declarations * ---------- */ -static void pgstat_main(int real_argc, char *real_argv[]); -static void pgstat_recvbuffer(int real_argc, char *real_argv[]); +static void pgstat_main(void); +static void pgstat_recvbuffer(void); static void pgstat_die(SIGNAL_ARGS); static int pgstat_add_backend(PgStat_MsgHdr *msg); @@ -246,13 +246,10 @@ pgstat_init(void) * * Called from postmaster at startup or after an existing collector * died. Fire up a fresh statistics collector. - * - * The process' original argc and argv are passed, because they are - * needed by init_ps_display() on some platforms. * ---------- */ int -pgstat_start(int real_argc, char *real_argv[]) +pgstat_start(void) { /* * Do nothing if no collector needed @@ -316,7 +313,7 @@ pgstat_start(int real_argc, char *real_argv[]) /* Close the postmaster's sockets, except for pgstat link */ ClosePostmasterPorts(false); - pgstat_main(real_argc, real_argv); + pgstat_main(); exit(0); } @@ -1104,7 +1101,7 @@ pgstat_send(void *msg, int len) * ---------- */ static void -pgstat_main(int real_argc, char *real_argv[]) +pgstat_main(void) { PgStat_Msg msg; fd_set rfds; @@ -1176,7 +1173,7 @@ pgstat_main(int real_argc, char *real_argv[]) default: /* parent becomes buffer process */ close(pgStatPipe[0]); - pgstat_recvbuffer(real_argc, real_argv); + pgstat_recvbuffer(); exit(0); } @@ -1192,7 +1189,7 @@ pgstat_main(int real_argc, char *real_argv[]) * WARNING: On some platforms the environment will be moved around to * make room for the ps display string. */ - init_ps_display(real_argc, real_argv, "stats collector process", "", ""); + init_ps_display("stats collector process", "", ""); set_ps_display(""); /* @@ -1451,7 +1448,7 @@ pgstat_main(int real_argc, char *real_argv[]) * ---------- */ static void -pgstat_recvbuffer(int real_argc, char *real_argv[]) +pgstat_recvbuffer(void) { fd_set rfds; fd_set wfds; @@ -1477,7 +1474,7 @@ pgstat_recvbuffer(int real_argc, char *real_argv[]) * WARNING: On some platforms the environment will be moved around to * make room for the ps display string. */ - init_ps_display(real_argc, real_argv, "stats buffer process", "", ""); + init_ps_display("stats buffer process", "", ""); set_ps_display(""); /* diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index c8f703880de..5009185952d 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -37,7 +37,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.249 2001/10/19 20:47:09 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.250 2001/10/21 03:25:35 tgl Exp $ * * NOTES * @@ -153,8 +153,6 @@ int MaxBackends = DEF_MAXBACKENDS; static char *progname = (char *) NULL; -static char **real_argv; -static int real_argc; /* flag to indicate that SIGHUP arrived during server loop */ static volatile bool got_SIGHUP = false; @@ -228,9 +226,6 @@ extern int optind, #ifdef HAVE_INT_OPTRESET extern int optreset; #endif -#ifdef HAVE_INT___GETOPT_INITIALIZED -extern int __getopt_initialized; -#endif /* * postmaster.c - function prototypes @@ -337,8 +332,6 @@ PostmasterMain(int argc, char *argv[]) *original_extraoptions = '\0'; progname = argv[0]; - real_argv = argv; - real_argc = argc; /* * Catch standard options before doing much else. This even works on @@ -444,10 +437,7 @@ PostmasterMain(int argc, char *argv[]) /* reset getopt(3) to rescan arguments */ optind = 1; #ifdef HAVE_INT_OPTRESET - optreset = 1; /* some systems need this */ -#endif -#ifdef HAVE_INT___GETOPT_INITIALIZED - __getopt_initialized = 0; /* glibc needs this */ + optreset = 1; /* some systems need this too */ #endif while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:Ss-:")) != EOF) @@ -599,10 +589,7 @@ PostmasterMain(int argc, char *argv[]) */ optind = 1; #ifdef HAVE_INT_OPTRESET - optreset = 1; /* some systems need this */ -#endif -#ifdef HAVE_INT___GETOPT_INITIALIZED - __getopt_initialized = 0; /* glibc needs this */ + optreset = 1; /* some systems need this too */ #endif /* For debugging: display postmaster environment */ @@ -620,6 +607,13 @@ PostmasterMain(int argc, char *argv[]) } /* + * On some systems our dynloader code needs the executable's pathname. + */ + if (FindExec(pg_pathname, progname, "postgres") < 0) + elog(FATAL, "%s: could not locate executable, bailing out...", + progname); + + /* * Initialize SSL library, if specified. */ #ifdef USE_SSL @@ -742,7 +736,7 @@ PostmasterMain(int argc, char *argv[]) */ if (pgstat_init() < 0) ExitPostmaster(1); - if (pgstat_start(real_argc, real_argv) < 0) + if (pgstat_start() < 0) ExitPostmaster(1); /* @@ -1570,7 +1564,7 @@ reaper(SIGNAL_ARGS) else if (WIFSIGNALED(exitstatus)) elog(DEBUG, "statistics collector was terminated by signal %d", WTERMSIG(exitstatus)); - pgstat_start(real_argc, real_argv); + pgstat_start(); continue; } @@ -1849,6 +1843,17 @@ BackendStartup(Port *port) MyCancelKey = PostmasterRandom(); /* + * Make room for backend data structure. Better before the fork() + * so we can handle failure cleanly. + */ + bn = (Backend *) malloc(sizeof(Backend)); + if (!bn) + { + elog(DEBUG, "out of memory; connection startup aborted"); + return STATUS_ERROR; + } + + /* * Flush stdio channels just before fork, to avoid double-output * problems. Ideally we'd use fflush(NULL) here, but there are still a * few non-ANSI stdio libraries out there (like SunOS 4.1.x) that @@ -1864,17 +1869,6 @@ BackendStartup(Port *port) beos_before_backend_startup(); #endif - /* - * Make room for backend data structure. Better before the fork() - * so we can handle failure cleanly. - */ - bn = (Backend *) malloc(sizeof(Backend)); - if (!bn) - { - elog(DEBUG, "out of memory; connection startup aborted"); - return STATUS_ERROR; - } - pid = fork(); if (pid == 0) /* child */ @@ -1912,8 +1906,8 @@ BackendStartup(Port *port) /* in parent, normal */ if (DebugLvl >= 1) - elog(DEBUG, "BackendStartup: pid=%d user=%s db=%s socket=%d\n", - pid, port->user, port->database, port->sock); + elog(DEBUG, "BackendStartup: forked pid=%d socket=%d", + pid, port->sock); /* * Everything's been successful, it's safe to add this backend to our @@ -2103,8 +2097,7 @@ DoBackend(Port *port) * optarg or getenv() from above will be invalid after this call. * Better use strdup or something similar. */ - init_ps_display(real_argc, real_argv, port->user, port->database, - remote_host); + init_ps_display(port->user, port->database, remote_host); set_ps_display("authentication"); /* @@ -2223,7 +2216,7 @@ DoBackend(Port *port) fprintf(stderr, ")\n"); } - return (PostgresMain(ac, av, real_argc, real_argv, port->user)); + return (PostgresMain(ac, av, port->user)); } /* @@ -2469,7 +2462,7 @@ SSDataBase(int xlop) statmsg = "??? subprocess"; break; } - init_ps_display(real_argc, real_argv, statmsg, "", ""); + init_ps_display(statmsg, "", ""); set_ps_display(""); /* Set up command-line arguments for subprocess */ @@ -2568,7 +2561,7 @@ CreateOptsFile(int argc, char *argv[]) FILE *fp; unsigned i; - if (FindExec(fullprogname, argv[0], "postmaster") == -1) + if (FindExec(fullprogname, argv[0], "postmaster") < 0) return false; filename = palloc(strlen(DataDir) + 20); |
