*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.45 2001/06/03 14:53:56 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.46 2001/10/21 03:25:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "miscadmin.h"
#include "bootstrap/bootstrap.h"
#include "tcop/tcopprot.h"
+#include "utils/ps_status.h"
int
main(int argc, char *argv[])
{
+ char **new_argv;
+ int i;
int len;
struct passwd *pw;
char *pw_name_persist;
beos_startup(argc, argv);
#endif
+ /*
+ * Not-quite-so-platform-specific startup environment checks. Still
+ * best to minimize these.
+ */
+
+ /* Initialize NLS settings so we can give localized error messages */
#ifdef ENABLE_NLS
#ifdef LC_MESSAGES
setlocale(LC_MESSAGES, "");
textdomain("postgres");
#endif
- /*
- * Not-quite-so-platform-specific startup environment checks. Still
- * best to minimize these.
- */
-
/*
* Skip permission checks if we're just trying to do --help or --version;
* otherwise root will get unhelpful failure messages from initdb.
setlocale(LC_MONETARY, "");
#endif
+ /*
+ * Remember the physical location of the initially given argv[] array,
+ * since on some platforms that storage must be overwritten in order
+ * to set the process title for ps. Then make a copy of the argv[]
+ * array for subsequent use, so that argument parsing doesn't get
+ * affected if init_ps_display overwrites the original argv[].
+ *
+ * (NB: do NOT think to remove this copying, even though postmaster.c
+ * finishes looking at argv[] long before we ever consider changing
+ * the ps display. On some platforms, getopt(3) keeps pointers into
+ * the argv array, and will get horribly confused when it is re-called
+ * to analyze a subprocess' argument string if the argv storage has
+ * been clobbered meanwhile.)
+ */
+ save_ps_display_args(argc, argv);
+
+ new_argv = (char **) malloc((argc + 1) * sizeof(char *));
+ for (i = 0; i < argc; i++)
+ new_argv[i] = strdup(argv[i]);
+ new_argv[argc] = NULL;
+
/*
* Now dispatch to one of PostmasterMain, PostgresMain, or
* BootstrapMain depending on the program name (and possibly first
* argument) we were called with. The lack of consistency here is
* historical.
*/
- len = strlen(argv[0]);
+ len = strlen(new_argv[0]);
- if (len >= 10 && strcmp(argv[0] + len - 10, "postmaster") == 0)
+ if (len >= 10 && strcmp(new_argv[0] + len - 10, "postmaster") == 0)
{
/* Called as "postmaster" */
- exit(PostmasterMain(argc, argv));
+ exit(PostmasterMain(argc, new_argv));
}
/*
* If the first argument is "-boot", then invoke bootstrap mode. Note
* we remove "-boot" from the arguments passed on to BootstrapMain.
*/
- if (argc > 1 && strcmp(argv[1], "-boot") == 0)
- exit(BootstrapMain(argc - 1, argv + 1));
+ if (argc > 1 && strcmp(new_argv[1], "-boot") == 0)
+ exit(BootstrapMain(argc - 1, new_argv + 1));
/*
* Otherwise we're a standalone backend. Invoke PostgresMain,
if (pw == NULL)
{
fprintf(stderr, gettext("%s: invalid current euid %d\n"),
- argv[0], (int) geteuid());
+ new_argv[0], (int) geteuid());
exit(1);
}
/* Allocate new memory because later getpwuid() calls can overwrite it */
pw_name_persist = strdup(pw->pw_name);
- exit(PostgresMain(argc, argv, argc, argv, pw_name_persist));
+ exit(PostgresMain(argc, new_argv, pw_name_persist));
}
*
* 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"
* 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);
*
* 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
/* Close the postmaster's sockets, except for pgstat link */
ClosePostmasterPorts(false);
- pgstat_main(real_argc, real_argv);
+ pgstat_main();
exit(0);
}
* ----------
*/
static void
-pgstat_main(int real_argc, char *real_argv[])
+pgstat_main(void)
{
PgStat_Msg msg;
fd_set rfds;
default:
/* parent becomes buffer process */
close(pgStatPipe[0]);
- pgstat_recvbuffer(real_argc, real_argv);
+ pgstat_recvbuffer();
exit(0);
}
* 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("");
/*
* ----------
*/
static void
-pgstat_recvbuffer(int real_argc, char *real_argv[])
+pgstat_recvbuffer(void)
{
fd_set rfds;
fd_set wfds;
* 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("");
/*
*
*
* 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
*
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;
#ifdef HAVE_INT_OPTRESET
extern int optreset;
#endif
-#ifdef HAVE_INT___GETOPT_INITIALIZED
-extern int __getopt_initialized;
-#endif
/*
* postmaster.c - function prototypes
*original_extraoptions = '\0';
progname = argv[0];
- real_argv = argv;
- real_argc = argc;
/*
* Catch standard options before doing much else. This even works on
/* 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)
*/
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 */
fprintf(stderr, "-----------------------------------------\n");
}
+ /*
+ * 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.
*/
*/
if (pgstat_init() < 0)
ExitPostmaster(1);
- if (pgstat_start(real_argc, real_argv) < 0)
+ if (pgstat_start() < 0)
ExitPostmaster(1);
/*
else if (WIFSIGNALED(exitstatus))
elog(DEBUG, "statistics collector was terminated by signal %d",
WTERMSIG(exitstatus));
- pgstat_start(real_argc, real_argv);
+ pgstat_start();
continue;
}
*/
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
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 */
/* 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
* 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");
/*
fprintf(stderr, ")\n");
}
- return (PostgresMain(ac, av, real_argc, real_argv, port->user));
+ return (PostgresMain(ac, av, port->user));
}
/*
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 */
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);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.237 2001/10/19 18:19:41 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.238 2001/10/21 03:25:35 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
bool InError = false;
static bool EchoQuery = false; /* default don't echo */
-char pg_pathname[MAXPGPATH];
FILE *StatFp = NULL;
/* ----------------
* PostgresMain
* postgres main loop -- all backends, interactive or otherwise start here
*
- * argc/argv are the command line arguments to be used. When being forked
- * by the postmaster, these are not the original argv array of the process.
- * real_argc/real_argv point to the original argv array, which is needed by
- * `ps' display on some platforms. username is the (possibly authenticated)
- * PostgreSQL user name to be used for the session.
+ * argc/argv are the command line arguments to be used. (When being forked
+ * by the postmaster, these are not the original argv array of the process.)
+ * username is the (possibly authenticated) PostgreSQL user name to be used
+ * for the session.
* ----------------------------------------------------------------
*/
int
-PostgresMain(int argc, char *argv[],
- int real_argc, char *real_argv[],
- const char *username)
+PostgresMain(int argc, char *argv[], const char *username)
{
int flag;
proc_exit(1);
}
+ /*
+ * On some systems our dynloader code needs the executable's
+ * pathname. (If under postmaster, this was done already.)
+ */
+ if (FindExec(pg_pathname, argv[0], "postgres") < 0)
+ elog(FATAL, "%s: could not locate executable, bailing out...",
+ argv[0]);
+
/*
* Validate we have been given a reasonable-looking DataDir
* (if under postmaster, assume postmaster did this already).
SetCharSet();
#endif
- /* On some systems our dynloader code needs the executable's pathname */
- if (FindExec(pg_pathname, real_argv[0], "postgres") < 0)
- elog(FATAL, "%s: could not locate executable, bailing out...",
- real_argv[0]);
-
/*
* General initialization.
*
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
- puts("$Revision: 1.237 $ $Date: 2001/10/19 18:19:41 $\n");
+ puts("$Revision: 1.238 $ $Date: 2001/10/21 03:25:35 $\n");
}
/*
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.60 2001/09/21 03:32:35 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.61 2001/10/21 03:25:35 tgl Exp $
*
* NOTES
* Globals used all over the place should be declared here and not
Relation reldesc; /* current relation descriptor */
-char OutputFileName[MAXPGPATH] = "";
+char OutputFileName[MAXPGPATH];
+
+char pg_pathname[MAXPGPATH]; /* full path to postgres executable */
BackendId MyBackendId;
* ps_status.c
*
* Routines to support changing the ps display of PostgreSQL backends
- * to contain some useful information. Differs wildly across
+ * to contain some useful information. Mechanism differs wildly across
* platforms.
*
- * $Header: /cvsroot/pgsql/src/backend/utils/misc/ps_status.c,v 1.5 2001/10/05 15:47:48 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/misc/ps_status.c,v 1.6 2001/10/21 03:25:35 tgl Exp $
*
* Copyright 2000 by PostgreSQL Global Development Group
* various details abducted from various places
#include "postgres.h"
#include
-
-
#ifdef HAVE_SYS_PSTAT_H
#include /* for HP-UX */
#endif
#endif
#include "miscadmin.h"
-
#include "utils/ps_status.h"
extern char **environ;
static size_t ps_buffer_fixed_size; /* size of the constant prefix */
+/* save the original argv[] location here */
+static int save_argc;
+static char **save_argv;
/*
- * Call this once at backend start.
+ * Call this early in startup to save the original argc/argv values.
+ * argv[] will not be overwritten by this routine, but may be overwritten
+ * during init_ps_display.
*/
void
-init_ps_display(int argc, char *argv[],
- const char *username, const char *dbname,
+save_ps_display_args(int argc, char *argv[])
+{
+ save_argc = argc;
+ save_argv = argv;
+}
+
+/*
+ * Call this once during subprocess startup to set the identification
+ * values. At this point, the original argv[] array may be overwritten.
+ */
+void
+init_ps_display(const char *username, const char *dbname,
const char *host_info)
{
#ifndef PS_USE_NONE
if (!IsUnderPostmaster)
return;
+ /* no ps display if you didn't call save_ps_display_args() */
+ if (!save_argv)
+ return;
+
#ifdef PS_USE_CHANGE_ARGV
- argv[0] = ps_buffer;
- argv[1] = NULL;
+ save_argv[0] = ps_buffer;
+ save_argv[1] = NULL;
#endif /* PS_USE_CHANGE_ARGV */
#ifdef PS_USE_CLOBBER_ARGV
/*
* check for contiguous argv strings
*/
- for (i = 0; i < argc; i++)
- if (i == 0 || end_of_area + 1 == argv[i])
- end_of_area = argv[i] + strlen(argv[i]);
+ for (i = 0; i < save_argc; i++)
+ if (i == 0 || end_of_area + 1 == save_argv[i])
+ end_of_area = save_argv[i] + strlen(save_argv[i]);
/*
* check for contiguous environ strings following argv
{
ps_buffer = NULL;
ps_buffer_size = 0;
+ return;
}
else
{
- ps_buffer = argv[0];
- ps_buffer_size = end_of_area - argv[0] - 1;
+ ps_buffer = save_argv[0];
+ ps_buffer_size = end_of_area - save_argv[0] - 1;
}
- argv[1] = NULL;
+ save_argv[1] = NULL;
/*
* move the environment out of the way
* indication of what you're currently doing passed in the argument.
*/
void
-set_ps_display(const char *value)
+set_ps_display(const char *activity)
{
#ifndef PS_USE_NONE
/* no ps display for stand-alone backend */
return;
#endif
- /* Update ps_buffer to contain both fixed part and value */
- StrNCpy(ps_buffer + ps_buffer_fixed_size, value,
+ /* Update ps_buffer to contain both fixed part and activity */
+ StrNCpy(ps_buffer + ps_buffer_fixed_size, activity,
ps_buffer_size - ps_buffer_fixed_size);
/* Transmit new setting to kernel, if necessary */
/*
* Returns what's currently in the ps display, in case someone needs
- * it. Note that only the variable part is returned.
+ * it. Note that only the activity part is returned.
*/
const char *
get_ps_display(void)
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: miscadmin.h,v 1.93 2001/09/29 04:02:26 tgl Exp $
+ * $Id: miscadmin.h,v 1.94 2001/10/21 03:25:35 tgl Exp $
*
* NOTES
* some of the information in this file should be moved to
extern long MyCancelKey;
extern char OutputFileName[];
+extern char pg_pathname[];
/*
* done in storage/backendid.h for now.
*
* Copyright (c) 2001, PostgreSQL Global Development Group
*
- * $Id: pgstat.h,v 1.7 2001/09/03 12:00:00 petere Exp $
+ * $Id: pgstat.h,v 1.8 2001/10/21 03:25:36 tgl Exp $
* ----------
*/
#ifndef PGSTAT_H
* ----------
*/
extern int pgstat_init(void);
-extern int pgstat_start(int real_argc, char *real_argv[]);
+extern int pgstat_start(void);
extern int pgstat_ispgstat(int pid);
extern void pgstat_close_sockets(void);
extern void pgstat_beterm(int pid);
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: tcopprot.h,v 1.42 2001/09/07 16:12:49 wieck Exp $
+ * $Id: tcopprot.h,v 1.43 2001/10/21 03:25:36 tgl Exp $
*
* OLD COMMENTS
* This file was created so that other c files could get the two
extern void die(SIGNAL_ARGS);
extern void quickdie(SIGNAL_ARGS);
extern void authdie(SIGNAL_ARGS);
-extern int PostgresMain(int argc, char *argv[],
- int real_argc, char *real_argv[], const char *username);
+extern int PostgresMain(int argc, char *argv[], const char *username);
extern void ResetUsage(void);
extern void ShowUsage(void);
extern FILE *StatFp;
*
* Declarations for backend/utils/misc/ps_status.c
*
+ * $Id: ps_status.h,v 1.20 2001/10/21 03:25:36 tgl Exp $
+ *
*-------------------------------------------------------------------------
*/
#ifndef PS_STATUS_H
#define PS_STATUS_H
-void init_ps_display(int argc, char *argv[],
- const char *username, const char *dbname,
- const char *host_info);
+extern void save_ps_display_args(int argc, char *argv[]);
+
+extern void init_ps_display(const char *username, const char *dbname,
+ const char *host_info);
-void
- set_ps_display(const char *value);
+extern void set_ps_display(const char *activity);
-const char *
- get_ps_display(void);
+extern const char *get_ps_display(void);
#endif /* PS_STATUS_H */