aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/Makefile7
-rw-r--r--src/backend/commands/async.c6
-rw-r--r--src/backend/libpq/pqcomm.c9
-rw-r--r--src/backend/postmaster/postmaster.c125
-rw-r--r--src/backend/storage/lmgr/lock.c20
-rw-r--r--src/backend/tcop/postgres.c91
-rw-r--r--src/backend/tcop/pquery.c4
-rw-r--r--src/backend/tcop/utility.c102
-rw-r--r--src/backend/utils/misc/Makefile4
-rw-r--r--src/backend/utils/misc/guc-file.l20
-rw-r--r--src/backend/utils/misc/postgresql.conf.sample20
-rw-r--r--src/backend/utils/misc/ps_status.c254
12 files changed, 425 insertions, 237 deletions
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 3fc5d3fa6b7..78a7cd7805f 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -34,7 +34,7 @@
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.52 2000/05/31 00:28:13 petere Exp $
+# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.53 2000/06/04 01:44:28 petere Exp $
#
#-------------------------------------------------------------------------
@@ -205,7 +205,8 @@ endif
install-templates: $(TEMPLATEDIR) \
global1.bki.source local1_template1.bki.source \
global1.description local1_template1.description \
- libpq/pg_hba.conf.sample libpq/pg_ident.conf.sample
+ libpq/pg_hba.conf.sample libpq/pg_ident.conf.sample \
+ utils/misc/postgresql.conf.sample
$(INSTALL) $(INSTLOPTS) global1.bki.source \
$(TEMPLATEDIR)/global1.bki.source
$(INSTALL) $(INSTLOPTS) global1.description \
@@ -218,6 +219,8 @@ install-templates: $(TEMPLATEDIR) \
$(TEMPLATEDIR)/pg_hba.conf.sample
$(INSTALL) $(INSTLOPTS) libpq/pg_ident.conf.sample \
$(TEMPLATEDIR)/pg_ident.conf.sample
+ $(INSTALL) $(INSTLOPTS) utils/misc/postgresql.conf.sample \
+ $(TEMPLATEDIR)/postgresql.conf.sample
install-headers: prebuildheaders $(SRCDIR)/include/config.h
-@if [ ! -d $(HEADERDIR) ]; then mkdir $(HEADERDIR); fi
diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c
index a1eb3598bdd..23396108c80 100644
--- a/src/backend/commands/async.c
+++ b/src/backend/commands/async.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.62 2000/05/31 00:28:15 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.63 2000/06/04 01:44:29 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -771,7 +771,7 @@ ProcessIncomingNotify(void)
if (Trace_notify)
elog(DEBUG, "ProcessIncomingNotify");
- PS_SET_STATUS("async_notify");
+ set_ps_display("async_notify");
notifyInterruptOccurred = 0;
@@ -841,7 +841,7 @@ ProcessIncomingNotify(void)
*/
pq_flush();
- PS_SET_STATUS("idle");
+ set_ps_display("idle");
if (Trace_notify)
elog(DEBUG, "ProcessIncomingNotify: done");
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index 44c1dd91a01..cc2d0c27548 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -29,7 +29,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: pqcomm.c,v 1.94 2000/06/02 15:57:21 momjian Exp $
+ * $Id: pqcomm.c,v 1.95 2000/06/04 01:44:30 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -182,12 +182,11 @@ StreamDoUnlink()
*/
int
-StreamServerPort(char *hostName, unsigned short portName, int *fdP)
+StreamServerPort(int family, unsigned short portName, int *fdP)
{
SockAddr saddr;
int fd,
- err,
- family;
+ err;
size_t len;
int one = 1;
@@ -196,7 +195,7 @@ StreamServerPort(char *hostName, unsigned short portName, int *fdP)
#endif
- family = ((hostName != NULL) ? AF_INET : AF_UNIX);
+ Assert(family == AF_INET || family == AF_UNIX);
if ((fd = socket(family, SOCK_STREAM, 0)) < 0)
{
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index bad51715b28..b578bc038f7 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.145 2000/06/02 15:57:22 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.146 2000/06/04 01:44:31 petere Exp $
*
* NOTES
*
@@ -33,6 +33,8 @@
*
*-------------------------------------------------------------------------
*/
+#include "postgres.h"
+
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
@@ -46,16 +48,11 @@
#include <time.h>
#include <sys/param.h>
-#include "postgres.h"
/* moved here to prevent double define */
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
-#ifndef MAXHOSTNAMELEN
-#define MAXHOSTNAMELEN 256
-#endif
-
#ifdef HAVE_LIMITS_H
#include <limits.h>
#else
@@ -72,10 +69,6 @@
#include "getopt.h"
#endif
-#ifndef HAVE_GETHOSTNAME
-#include "port-protos.h"
-#endif
-
#include "commands/async.h"
#include "lib/dllist.h"
#include "libpq/auth.h"
@@ -191,8 +184,6 @@ static volatile bool got_SIGHUP = false;
/*
* Default Values
*/
-static char Execfile[MAXPGPATH];
-
static int ServerSock_INET = INVALID_SOCK; /* stream socket server */
#if !defined(__CYGWIN32__) && !defined(__QNX__)
@@ -278,7 +269,7 @@ static void SignalChildren(SIGNAL_ARGS);
static int CountChildren(void);
static int
SetOptsFile(char *progname, int port, char *datadir,
- int assert, int nbuf, char *execfile,
+ int assert, int nbuf,
int debuglvl, int netserver,
#ifdef USE_SSL
int securenetserver,
@@ -368,62 +359,18 @@ int
PostmasterMain(int argc, char *argv[])
{
int opt;
- char *hostName;
int status;
int silentflag = 0;
bool DataDirOK; /* We have a usable PGDATA value */
- char hostbuf[MAXHOSTNAMELEN];
- int nonblank_argc;
char original_extraoptions[MAXPGPATH];
*original_extraoptions = '\0';
-#ifndef HAVE_SETPROCTITLE
- /*
- * We need four params so we can display status. If we don't get
- * them from the user, let's make them ourselves.
- */
- if (argc < 5)
- {
- int i;
- char *new_argv[6];
-
- for (i = 0; i < argc; i++)
- new_argv[i] = argv[i];
- for (; i < 5; i++)
- new_argv[i] = "";
- new_argv[5] = NULL;
-
- if (!Execfile[0] && FindExec(Execfile, argv[0], "postmaster") < 0)
- {
- fprintf(stderr, "%s: could not find postmaster to execute...\n",
- argv[0]);
- exit(1);
- }
- new_argv[0] = Execfile;
-
- execv(new_argv[0], new_argv);
-
- /* How did we get here? Error! */
- perror(new_argv[0]);
- fprintf(stderr, "PostmasterMain execv failed on %s\n", argv[0]);
- exit(1);
- }
-#endif
-
progname = argv[0];
real_argv = argv;
real_argc = argc;
/*
- * don't process any dummy args we placed at the end for status
- * display
- */
- for (nonblank_argc = argc; nonblank_argc > 0; nonblank_argc--)
- if (argv[nonblank_argc - 1] != NULL && argv[nonblank_argc - 1][0] != '\0')
- break;
-
- /*
* for security, no dir or file created can be group or other
* accessible
*/
@@ -431,13 +378,6 @@ PostmasterMain(int argc, char *argv[])
ResetAllOptions();
- if (!(hostName = getenv("PGHOST")))
- {
- if (gethostname(hostbuf, MAXHOSTNAMELEN) < 0)
- strcpy(hostbuf, "localhost");
- hostName = hostbuf;
- }
-
MyProcPid = getpid();
DataDir = getenv("PGDATA"); /* default value */
@@ -455,7 +395,7 @@ PostmasterMain(int argc, char *argv[])
* will occur.
*/
opterr = 1;
- while ((opt = getopt(nonblank_argc, argv, "A:a:B:b:D:d:Film:MN:no:p:Ss-:")) != EOF)
+ while ((opt = getopt(argc, argv, "A:a:B:b:D:d:Film:MN:no:p:Ss-:")) != EOF)
{
if (opt == 'D')
DataDir = optarg;
@@ -472,7 +412,7 @@ PostmasterMain(int argc, char *argv[])
ProcessConfigFile(PGC_POSTMASTER);
IgnoreSystemIndexes(false);
- while ((opt = getopt(nonblank_argc, argv, "A:a:B:b:D:d:Film:MN:no:p:Ss-:")) != EOF)
+ while ((opt = getopt(argc, argv, "A:a:B:b:D:d:Film:MN:no:p:Ss-:")) != EOF)
{
switch (opt)
{
@@ -496,15 +436,7 @@ PostmasterMain(int argc, char *argv[])
NBuffers = atoi(optarg);
break;
case 'b':
- /* Set the backend executable file to use. */
- if (!ValidateBinary(optarg))
- StrNCpy(Execfile, optarg, MAXPGPATH);
- else
- {
- fprintf(stderr, "%s: invalid backend \"%s\"\n",
- progname, optarg);
- exit(2);
- }
+ /* Can no longer set the backend executable file to use. */
break;
case 'D':
/* already done above */
@@ -630,13 +562,6 @@ PostmasterMain(int argc, char *argv[])
exit(1);
}
- if (!Execfile[0] && FindExec(Execfile, argv[0], "postgres") < 0)
- {
- fprintf(stderr, "%s: could not find backend to execute...\n",
- argv[0]);
- exit(1);
- }
-
#ifdef USE_SSL
if (!NetServer && SecureNetServer)
{
@@ -649,7 +574,7 @@ PostmasterMain(int argc, char *argv[])
if (NetServer)
{
- status = StreamServerPort(hostName, (unsigned short)PostPortName, &ServerSock_INET);
+ status = StreamServerPort(AF_INET, (unsigned short)PostPortName, &ServerSock_INET);
if (status != STATUS_OK)
{
fprintf(stderr, "%s: cannot create INET stream port\n",
@@ -659,7 +584,7 @@ PostmasterMain(int argc, char *argv[])
}
#if !defined(__CYGWIN32__) && !defined(__QNX__)
- status = StreamServerPort(NULL, (unsigned short)PostPortName, &ServerSock_UNIX);
+ status = StreamServerPort(AF_UNIX, (unsigned short)PostPortName, &ServerSock_UNIX);
if (status != STATUS_OK)
{
fprintf(stderr, "%s: cannot create UNIX stream port\n",
@@ -696,7 +621,6 @@ PostmasterMain(int argc, char *argv[])
assert_enabled, /* whether -A is specified
* or not */
NBuffers, /* -B: number of shared buffers */
- Execfile, /* -b: postgres executable file */
DebugLvl, /* -d: debug level */
NetServer, /* -i: accept connection from INET */
#ifdef USE_SSL
@@ -785,7 +709,6 @@ pmdaemonize(char *extraoptions)
assert_enabled, /* whether -A is specified
* or not */
NBuffers, /* -B: number of shared buffers */
- Execfile, /* -b: postgres executable file */
DebugLvl, /* -d: debug level */
NetServer, /* -i: accept connection from INET */
#ifdef USE_SSL
@@ -1905,7 +1828,6 @@ DoBackend(Port *port)
{
char *av[ARGV_SIZE * 2];
int ac = 0;
- char execbuf[MAXPGPATH];
char debugbuf[ARGV_SIZE];
char protobuf[ARGV_SIZE];
char dbbuf[ARGV_SIZE];
@@ -1958,26 +1880,7 @@ DoBackend(Port *port)
* ----------------
*/
- StrNCpy(execbuf, Execfile, MAXPGPATH);
- av[ac++] = execbuf;
-
- /*
- * We need to set our argv[0] to an absolute path name because some
- * OS's use this for dynamic loading, like BSDI. Without it, when we
- * change directories to the database dir, the dynamic loader can't
- * find the base executable and fails. Another advantage is that this
- * changes the 'ps' displayed process name on some platforms. It does
- * on BSDI. That's a big win.
- */
-
-#ifndef linux
-
- /*
- * This doesn't work on linux and overwrites the only valid pointer to
- * the argv buffer. See PS_INIT_STATUS macro.
- */
- real_argv[0] = Execfile;
-#endif
+ av[ac++] = "postgres";
/*
* Pass the requested debugging level along to the backend. Level one
@@ -2229,7 +2132,6 @@ SSDataBase(bool startup)
{
char *av[ARGV_SIZE * 2];
int ac = 0;
- char execbuf[MAXPGPATH];
char nbbuf[ARGV_SIZE];
char dbbuf[ARGV_SIZE];
@@ -2244,8 +2146,7 @@ SSDataBase(bool startup)
ServerSock_UNIX = INVALID_SOCK;
#endif
- StrNCpy(execbuf, Execfile, MAXPGPATH);
- av[ac++] = execbuf;
+ av[ac++] = "postgres";
av[ac++] = "-d";
@@ -2294,7 +2195,7 @@ SSDataBase(bool startup)
*/
static int
SetOptsFile(char *progname, int port, char *datadir,
- int assert, int nbuf, char *execfile,
+ int assert, int nbuf,
int debuglvl, int netserver,
#ifdef USE_SSL
int securenetserver,
@@ -2324,7 +2225,7 @@ SetOptsFile(char *progname, int port, char *datadir,
strcat(opts, buf);
}
- snprintf(buf, sizeof(buf), "-B %d\n-b %s\n", nbuf, execfile);
+ snprintf(buf, sizeof(buf), "-B %d\n", nbuf);
strcat(opts, buf);
if (debuglvl)
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index 0b3bdbf64d8..d18739497bd 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.68 2000/05/31 00:28:30 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.69 2000/06/04 01:44:32 petere Exp $
*
* NOTES
* Outside modules can create a lock table and acquire/release
@@ -895,8 +895,7 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCK *lock, LOCKMODE lockmode)
{
PROC_QUEUE *waitQueue = &(lock->waitProcs);
LOCKMETHODTABLE *lockMethodTable = LockMethodTable[lockmethod];
- char old_status[64],
- new_status[64];
+ char *new_status, *old_status;
Assert(lockmethod < NumLockMethods);
@@ -909,10 +908,13 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCK *lock, LOCKMODE lockmode)
* people can be deleted from the queue by a SIGINT or something.
*/
LOCK_PRINT("WaitOnLock: sleeping on lock", lock, lockmode);
- strcpy(old_status, PS_STATUS);
- strcpy(new_status, PS_STATUS);
+
+ old_status = pstrdup(get_ps_display());
+ new_status = palloc(strlen(get_ps_display()) + 10);
+ strcpy(new_status, get_ps_display());
strcat(new_status, " waiting");
- PS_SET_STATUS(new_status);
+ set_ps_display(new_status);
+
if (ProcSleep(waitQueue,
lockMethodTable->ctl,
lockmode,
@@ -940,7 +942,11 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCK *lock, LOCKMODE lockmode)
if (lock->activeHolders[lockmode] == lock->holders[lockmode])
lock->waitMask &= BITS_OFF[lockmode];
- PS_SET_STATUS(old_status);
+
+ set_ps_display(old_status);
+ pfree(old_status);
+ pfree(new_status);
+
LOCK_PRINT("WaitOnLock: wakeup on lock", lock, lockmode);
return STATUS_OK;
}
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 99bc4575c59..0595f38fe4b 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.157 2000/05/31 00:28:31 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.158 2000/06/04 01:44:33 petere Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@@ -79,10 +79,6 @@ bool Log_connections = false;
CommandDest whereToSendOutput = Debug;
-/* Define status buffer needed by PS_SET_STATUS */
-#ifdef PS_DEFINE_BUFFER
-PS_DEFINE_BUFFER;
-#endif
extern void BaseInit(void);
extern void StartupXLOG(void);
@@ -815,10 +811,8 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
StringInfo parser_input;
char *userName;
- /* Used if verbose is set, must be initialized */
- char *remote_info = "interactive";
- char *remote_host = "";
- unsigned short remote_port = 0;
+ char *remote_host;
+ unsigned short remote_port;
extern int optind;
extern char *optarg;
@@ -1174,6 +1168,12 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
}
/*
+ * Make a copy of DataDir because the arguments and environment
+ * might be moved around later on.
+ */
+ DataDir = strdup(DataDir);
+
+ /*
* 1. Set BlockSig and UnBlockSig masks. 2. Set up signal handlers. 3.
* Allow only SIGUSR1 signal (we never block it) during
* initialization.
@@ -1281,55 +1281,56 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
#endif
/* On some systems our dynloader code needs the executable's pathname */
- if (FindExec(pg_pathname, argv[0], "postgres") < 0)
+ if (FindExec(pg_pathname, real_argv[0], "postgres") < 0)
elog(FATAL, "%s: could not locate executable, bailing out...",
- argv[0]);
+ real_argv[0]);
/*
* Find remote host name or address.
*/
+ remote_host = NULL;
+
if (IsUnderPostmaster)
{
- switch (MyProcPort->raddr.sa.sa_family)
+ if (MyProcPort->raddr.sa.sa_family == AF_INET)
{
- struct hostent *host_ent;
+ struct hostent *host_ent;
+ char * host_addr;
- case AF_INET:
- remote_info = remote_host = malloc(48);
- remote_port = ntohs(MyProcPort->raddr.in.sin_port);
- strcpy(remote_host, inet_ntoa(MyProcPort->raddr.in.sin_addr));
- if (HostnameLookup)
- {
- host_ent = \
- gethostbyaddr((char *) &MyProcPort->raddr.in.sin_addr,
- sizeof(MyProcPort->raddr.in.sin_addr),
- AF_INET);
- if (host_ent)
- {
- strncpy(remote_host, host_ent->h_name, 48);
- *(remote_host + 47) = '\0';
- }
- }
- if (ShowPortNumber)
+ remote_port = ntohs(MyProcPort->raddr.in.sin_port);
+ host_addr = inet_ntoa(MyProcPort->raddr.in.sin_addr);
+
+ if (HostnameLookup)
+ {
+ host_ent = gethostbyaddr((char *) &MyProcPort->raddr.in.sin_addr, sizeof(MyProcPort->raddr.in.sin_addr), AF_INET);
+
+ if (host_ent)
{
- remote_info = malloc(strlen(remote_host) + 6);
- sprintf(remote_info, "%s:%d", remote_host, remote_port);
+ remote_host = palloc(strlen(host_addr) + strlen(host_ent->h_name) + 3);
+ sprintf(remote_host, "%s[%s]", host_ent->h_name, host_addr);
}
- break;
- case AF_UNIX:
- remote_info = remote_host = "localhost";
- break;
- default:
- remote_info = remote_host = "unknown";
- break;
+ }
+
+ if (remote_host == NULL)
+ remote_host = pstrdup(host_addr);
+
+ if (ShowPortNumber)
+ {
+ char * str = palloc(strlen(remote_host) + 7);
+ sprintf(str, "%s:%hu", remote_host, remote_port);
+ pfree(remote_host);
+ remote_host = str;
+ }
}
+ else /* not AF_INET */
+ remote_host = "[local]";
+
/*
* Set process params for ps
*/
- PS_INIT_STATUS(real_argc, real_argv, argv[0],
- remote_info, userName, DBName);
- PS_SET_STATUS("startup");
+ init_ps_display(real_argc, real_argv, userName, DBName, remote_host);
+ set_ps_display("startup");
}
if (Log_connections)
@@ -1378,7 +1379,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
- puts("$Revision: 1.157 $ $Date: 2000/05/31 00:28:31 $\n");
+ puts("$Revision: 1.158 $ $Date: 2000/06/04 01:44:33 $\n");
}
/*
@@ -1422,7 +1423,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
for (;;)
{
- PS_SET_STATUS("idle");
+ set_ps_display("idle");
/* XXX this could be moved after ReadCommand below to get more
* sensical behaviour */
@@ -1565,7 +1566,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
{
if (DebugLvl >= 1)
elog(DEBUG, "CommitTransactionCommand");
- PS_SET_STATUS("commit");
+ set_ps_display("commit");
CommitTransactionCommand();
#ifdef SHOW_MEMORY_STATS
/* print global-context stats at each commit for leak tracking */
diff --git a/src/backend/tcop/pquery.c b/src/backend/tcop/pquery.c
index 0758a9532ad..dfc0f4e892b 100644
--- a/src/backend/tcop/pquery.c
+++ b/src/backend/tcop/pquery.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/pquery.c,v 1.30 2000/01/26 05:57:07 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/pquery.c,v 1.31 2000/06/04 01:44:33 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -204,7 +204,7 @@ ProcessQueryDesc(QueryDesc *queryDesc, Node *limoffset, Node *limcount)
plan = queryDesc->plantree;
operation = queryDesc->operation;
- PS_SET_STATUS(tag = CreateOperationTag(operation));
+ set_ps_display(tag = CreateOperationTag(operation));
dest = queryDesc->dest;
/* ----------------
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index c0a8352de43..2459b6507cd 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.88 2000/05/11 03:54:18 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.89 2000/06/04 01:44:33 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -92,18 +92,18 @@ ProcessUtility(Node *parsetree,
switch (stmt->command)
{
case BEGIN_TRANS:
- PS_SET_STATUS(commandTag = "BEGIN");
+ set_ps_display(commandTag = "BEGIN");
CHECK_IF_ABORTED();
BeginTransactionBlock();
break;
case COMMIT:
- PS_SET_STATUS(commandTag = "COMMIT");
+ set_ps_display(commandTag = "COMMIT");
EndTransactionBlock();
break;
case ROLLBACK:
- PS_SET_STATUS(commandTag = "ROLLBACK");
+ set_ps_display(commandTag = "ROLLBACK");
UserAbortTransactionBlock();
break;
}
@@ -118,7 +118,7 @@ ProcessUtility(Node *parsetree,
{
ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
- PS_SET_STATUS(commandTag = "CLOSE");
+ set_ps_display(commandTag = "CLOSE");
CHECK_IF_ABORTED();
PerformPortalClose(stmt->portalname, dest);
@@ -132,7 +132,7 @@ ProcessUtility(Node *parsetree,
bool forward;
int count;
- PS_SET_STATUS(commandTag = (stmt->ismove) ? "MOVE" : "FETCH");
+ set_ps_display(commandTag = (stmt->ismove) ? "MOVE" : "FETCH");
CHECK_IF_ABORTED();
SetQuerySnapshot();
@@ -155,7 +155,7 @@ ProcessUtility(Node *parsetree,
*
*/
case T_CreateStmt:
- PS_SET_STATUS(commandTag = "CREATE");
+ set_ps_display(commandTag = "CREATE");
CHECK_IF_ABORTED();
DefineRelation((CreateStmt *) parsetree, RELKIND_RELATION);
@@ -167,7 +167,7 @@ ProcessUtility(Node *parsetree,
List *args = stmt->relNames;
List *arg;
- PS_SET_STATUS(commandTag = "DROP");
+ set_ps_display(commandTag = "DROP");
CHECK_IF_ABORTED();
/* check as much as we can before we start dropping ... */
@@ -209,7 +209,7 @@ ProcessUtility(Node *parsetree,
{
Relation rel;
- PS_SET_STATUS(commandTag = "TRUNCATE");
+ set_ps_display(commandTag = "TRUNCATE");
CHECK_IF_ABORTED();
relname = ((TruncateStmt *) parsetree)->relName;
@@ -239,7 +239,7 @@ ProcessUtility(Node *parsetree,
statement = ((CommentStmt *) parsetree);
- PS_SET_STATUS(commandTag = "COMMENT");
+ set_ps_display(commandTag = "COMMENT");
CHECK_IF_ABORTED();
CommentObject(statement->objtype, statement->objname,
statement->objproperty, statement->objlist,
@@ -253,7 +253,7 @@ ProcessUtility(Node *parsetree,
{
CopyStmt *stmt = (CopyStmt *) parsetree;
- PS_SET_STATUS(commandTag = "COPY");
+ set_ps_display(commandTag = "COPY");
CHECK_IF_ABORTED();
if (stmt->direction != FROM)
@@ -282,7 +282,7 @@ ProcessUtility(Node *parsetree,
{
RenameStmt *stmt = (RenameStmt *) parsetree;
- PS_SET_STATUS(commandTag = "ALTER");
+ set_ps_display(commandTag = "ALTER");
CHECK_IF_ABORTED();
relname = stmt->relname;
@@ -336,7 +336,7 @@ ProcessUtility(Node *parsetree,
{
AlterTableStmt *stmt = (AlterTableStmt *) parsetree;
- PS_SET_STATUS(commandTag = "ALTER");
+ set_ps_display(commandTag = "ALTER");
CHECK_IF_ABORTED();
/*
@@ -375,7 +375,7 @@ ProcessUtility(Node *parsetree,
AclItem *aip;
unsigned modechg;
- PS_SET_STATUS(commandTag = "CHANGE");
+ set_ps_display(commandTag = "CHANGE");
CHECK_IF_ABORTED();
aip = stmt->aclitem;
@@ -411,7 +411,7 @@ ProcessUtility(Node *parsetree,
{
DefineStmt *stmt = (DefineStmt *) parsetree;
- PS_SET_STATUS(commandTag = "CREATE");
+ set_ps_display(commandTag = "CREATE");
CHECK_IF_ABORTED();
switch (stmt->defType)
@@ -435,14 +435,14 @@ ProcessUtility(Node *parsetree,
{
ViewStmt *stmt = (ViewStmt *) parsetree;
- PS_SET_STATUS(commandTag = "CREATE");
+ set_ps_display(commandTag = "CREATE");
CHECK_IF_ABORTED();
DefineView(stmt->viewname, stmt->query); /* retrieve parsetree */
}
break;
case T_ProcedureStmt: /* CREATE FUNCTION */
- PS_SET_STATUS(commandTag = "CREATE");
+ set_ps_display(commandTag = "CREATE");
CHECK_IF_ABORTED();
CreateFunction((ProcedureStmt *) parsetree, dest); /* everything */
break;
@@ -451,7 +451,7 @@ ProcessUtility(Node *parsetree,
{
IndexStmt *stmt = (IndexStmt *) parsetree;
- PS_SET_STATUS(commandTag = "CREATE");
+ set_ps_display(commandTag = "CREATE");
CHECK_IF_ABORTED();
DefineIndex(stmt->relname, /* relation name */
stmt->idxname, /* index name */
@@ -476,14 +476,14 @@ ProcessUtility(Node *parsetree,
if (aclcheck_result != ACLCHECK_OK)
elog(ERROR, "%s: %s", relname, aclcheck_error_strings[aclcheck_result]);
#endif
- PS_SET_STATUS(commandTag = "CREATE");
+ set_ps_display(commandTag = "CREATE");
CHECK_IF_ABORTED();
DefineQueryRewrite(stmt);
}
break;
case T_CreateSeqStmt:
- PS_SET_STATUS(commandTag = "CREATE");
+ set_ps_display(commandTag = "CREATE");
CHECK_IF_ABORTED();
DefineSequence((CreateSeqStmt *) parsetree);
@@ -493,7 +493,7 @@ ProcessUtility(Node *parsetree,
{
ExtendStmt *stmt = (ExtendStmt *) parsetree;
- PS_SET_STATUS(commandTag = "EXTEND");
+ set_ps_display(commandTag = "EXTEND");
CHECK_IF_ABORTED();
ExtendIndex(stmt->idxname, /* index name */
@@ -506,7 +506,7 @@ ProcessUtility(Node *parsetree,
{
RemoveStmt *stmt = (RemoveStmt *) parsetree;
- PS_SET_STATUS(commandTag = "DROP");
+ set_ps_display(commandTag = "DROP");
CHECK_IF_ABORTED();
switch (stmt->removeType)
@@ -568,7 +568,7 @@ ProcessUtility(Node *parsetree,
{
RemoveAggrStmt *stmt = (RemoveAggrStmt *) parsetree;
- PS_SET_STATUS(commandTag = "DROP");
+ set_ps_display(commandTag = "DROP");
CHECK_IF_ABORTED();
RemoveAggregate(stmt->aggname, stmt->aggtype);
}
@@ -578,7 +578,7 @@ ProcessUtility(Node *parsetree,
{
RemoveFuncStmt *stmt = (RemoveFuncStmt *) parsetree;
- PS_SET_STATUS(commandTag = "DROP");
+ set_ps_display(commandTag = "DROP");
CHECK_IF_ABORTED();
RemoveFunction(stmt->funcname,
length(stmt->args),
@@ -592,7 +592,7 @@ ProcessUtility(Node *parsetree,
char *type1 = (char *) NULL;
char *type2 = (char *) NULL;
- PS_SET_STATUS(commandTag = "DROP");
+ set_ps_display(commandTag = "DROP");
CHECK_IF_ABORTED();
if (lfirst(stmt->args) != NULL)
@@ -611,7 +611,7 @@ ProcessUtility(Node *parsetree,
{
CreatedbStmt *stmt = (CreatedbStmt *) parsetree;
- PS_SET_STATUS(commandTag = "CREATE DATABASE");
+ set_ps_display(commandTag = "CREATE DATABASE");
CHECK_IF_ABORTED();
createdb(stmt->dbname, stmt->dbpath, stmt->encoding);
}
@@ -621,7 +621,7 @@ ProcessUtility(Node *parsetree,
{
DropdbStmt *stmt = (DropdbStmt *) parsetree;
- PS_SET_STATUS(commandTag = "DROP DATABASE");
+ set_ps_display(commandTag = "DROP DATABASE");
CHECK_IF_ABORTED();
dropdb(stmt->dbname);
}
@@ -632,7 +632,7 @@ ProcessUtility(Node *parsetree,
{
NotifyStmt *stmt = (NotifyStmt *) parsetree;
- PS_SET_STATUS(commandTag = "NOTIFY");
+ set_ps_display(commandTag = "NOTIFY");
CHECK_IF_ABORTED();
Async_Notify(stmt->relname);
@@ -643,7 +643,7 @@ ProcessUtility(Node *parsetree,
{
ListenStmt *stmt = (ListenStmt *) parsetree;
- PS_SET_STATUS(commandTag = "LISTEN");
+ set_ps_display(commandTag = "LISTEN");
CHECK_IF_ABORTED();
Async_Listen(stmt->relname, MyProcPid);
@@ -654,7 +654,7 @@ ProcessUtility(Node *parsetree,
{
UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
- PS_SET_STATUS(commandTag = "UNLISTEN");
+ set_ps_display(commandTag = "UNLISTEN");
CHECK_IF_ABORTED();
Async_Unlisten(stmt->relname, MyProcPid);
@@ -669,7 +669,7 @@ ProcessUtility(Node *parsetree,
{
LoadStmt *stmt = (LoadStmt *) parsetree;
- PS_SET_STATUS(commandTag = "LOAD");
+ set_ps_display(commandTag = "LOAD");
CHECK_IF_ABORTED();
closeAllVfds(); /* probably not necessary... */
@@ -681,7 +681,7 @@ ProcessUtility(Node *parsetree,
{
ClusterStmt *stmt = (ClusterStmt *) parsetree;
- PS_SET_STATUS(commandTag = "CLUSTER");
+ set_ps_display(commandTag = "CLUSTER");
CHECK_IF_ABORTED();
cluster(stmt->relname, stmt->indexname);
@@ -689,7 +689,7 @@ ProcessUtility(Node *parsetree,
break;
case T_VacuumStmt:
- PS_SET_STATUS(commandTag = "VACUUM");
+ set_ps_display(commandTag = "VACUUM");
CHECK_IF_ABORTED();
vacuum(((VacuumStmt *) parsetree)->vacrel,
((VacuumStmt *) parsetree)->verbose,
@@ -701,7 +701,7 @@ ProcessUtility(Node *parsetree,
{
ExplainStmt *stmt = (ExplainStmt *) parsetree;
- PS_SET_STATUS(commandTag = "EXPLAIN");
+ set_ps_display(commandTag = "EXPLAIN");
CHECK_IF_ABORTED();
ExplainQuery(stmt->query, stmt->verbose, dest);
@@ -717,7 +717,7 @@ ProcessUtility(Node *parsetree,
{
RecipeStmt *stmt = (RecipeStmt *) parsetree;
- PS_SET_STATUS(commandTag = "EXECUTE RECIPE");
+ set_ps_display(commandTag = "EXECUTE RECIPE");
CHECK_IF_ABORTED();
beginRecipe(stmt);
}
@@ -732,7 +732,7 @@ ProcessUtility(Node *parsetree,
VariableSetStmt *n = (VariableSetStmt *) parsetree;
SetPGVariable(n->name, n->value);
- PS_SET_STATUS(commandTag = "SET VARIABLE");
+ set_ps_display(commandTag = "SET VARIABLE");
}
break;
@@ -741,7 +741,7 @@ ProcessUtility(Node *parsetree,
VariableShowStmt *n = (VariableShowStmt *) parsetree;
GetPGVariable(n->name);
- PS_SET_STATUS(commandTag = "SHOW VARIABLE");
+ set_ps_display(commandTag = "SHOW VARIABLE");
}
break;
@@ -750,7 +750,7 @@ ProcessUtility(Node *parsetree,
VariableResetStmt *n = (VariableResetStmt *) parsetree;
ResetPGVariable(n->name);
- PS_SET_STATUS(commandTag = "RESET VARIABLE");
+ set_ps_display(commandTag = "RESET VARIABLE");
}
break;
@@ -758,14 +758,14 @@ ProcessUtility(Node *parsetree,
* ******************************** TRIGGER statements *******************************
*/
case T_CreateTrigStmt:
- PS_SET_STATUS(commandTag = "CREATE");
+ set_ps_display(commandTag = "CREATE");
CHECK_IF_ABORTED();
CreateTrigger((CreateTrigStmt *) parsetree);
break;
case T_DropTrigStmt:
- PS_SET_STATUS(commandTag = "DROP");
+ set_ps_display(commandTag = "DROP");
CHECK_IF_ABORTED();
DropTrigger((DropTrigStmt *) parsetree);
@@ -775,14 +775,14 @@ ProcessUtility(Node *parsetree,
* ************* PROCEDURAL LANGUAGE statements *****************
*/
case T_CreatePLangStmt:
- PS_SET_STATUS(commandTag = "CREATE");
+ set_ps_display(commandTag = "CREATE");
CHECK_IF_ABORTED();
CreateProceduralLanguage((CreatePLangStmt *) parsetree);
break;
case T_DropPLangStmt:
- PS_SET_STATUS(commandTag = "DROP");
+ set_ps_display(commandTag = "DROP");
CHECK_IF_ABORTED();
DropProceduralLanguage((DropPLangStmt *) parsetree);
@@ -793,56 +793,56 @@ ProcessUtility(Node *parsetree,
*
*/
case T_CreateUserStmt:
- PS_SET_STATUS(commandTag = "CREATE USER");
+ set_ps_display(commandTag = "CREATE USER");
CHECK_IF_ABORTED();
CreateUser((CreateUserStmt *) parsetree);
break;
case T_AlterUserStmt:
- PS_SET_STATUS(commandTag = "ALTER USER");
+ set_ps_display(commandTag = "ALTER USER");
CHECK_IF_ABORTED();
AlterUser((AlterUserStmt *) parsetree);
break;
case T_DropUserStmt:
- PS_SET_STATUS(commandTag = "DROP USER");
+ set_ps_display(commandTag = "DROP USER");
CHECK_IF_ABORTED();
DropUser((DropUserStmt *) parsetree);
break;
case T_LockStmt:
- PS_SET_STATUS(commandTag = "LOCK TABLE");
+ set_ps_display(commandTag = "LOCK TABLE");
CHECK_IF_ABORTED();
LockTableCommand((LockStmt *) parsetree);
break;
case T_ConstraintsSetStmt:
- PS_SET_STATUS(commandTag = "SET CONSTRAINTS");
+ set_ps_display(commandTag = "SET CONSTRAINTS");
CHECK_IF_ABORTED();
DeferredTriggerSetState((ConstraintsSetStmt *) parsetree);
break;
case T_CreateGroupStmt:
- PS_SET_STATUS(commandTag = "CREATE GROUP");
+ set_ps_display(commandTag = "CREATE GROUP");
CHECK_IF_ABORTED();
CreateGroup((CreateGroupStmt *) parsetree);
break;
case T_AlterGroupStmt:
- PS_SET_STATUS(commandTag = "ALTER GROUP");
+ set_ps_display(commandTag = "ALTER GROUP");
CHECK_IF_ABORTED();
AlterGroup((AlterGroupStmt *) parsetree, "ALTER GROUP");
break;
case T_DropGroupStmt:
- PS_SET_STATUS(commandTag = "DROP GROUP");
+ set_ps_display(commandTag = "DROP GROUP");
CHECK_IF_ABORTED();
DropGroup((DropGroupStmt *) parsetree);
@@ -852,7 +852,7 @@ ProcessUtility(Node *parsetree,
{
ReindexStmt *stmt = (ReindexStmt *) parsetree;
- PS_SET_STATUS(commandTag = "REINDEX");
+ set_ps_display(commandTag = "REINDEX");
CHECK_IF_ABORTED();
switch (stmt->reindexType)
diff --git a/src/backend/utils/misc/Makefile b/src/backend/utils/misc/Makefile
index 30c7f768350..9c97e4a08a5 100644
--- a/src/backend/utils/misc/Makefile
+++ b/src/backend/utils/misc/Makefile
@@ -4,14 +4,14 @@
# Makefile for utils/misc
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/backend/utils/misc/Makefile,v 1.15 2000/06/01 14:52:25 tgl Exp $
+# $Header: /cvsroot/pgsql/src/backend/utils/misc/Makefile,v 1.16 2000/06/04 01:44:34 petere Exp $
#
#-------------------------------------------------------------------------
SRCDIR = ../../..
include $(SRCDIR)/Makefile.global
-OBJS = database.o superuser.o guc.o guc-file.o
+OBJS = database.o superuser.o guc.o guc-file.o ps_status.o
all: SUBSYS.o
diff --git a/src/backend/utils/misc/guc-file.l b/src/backend/utils/misc/guc-file.l
index eff6e195d58..c056af9ace0 100644
--- a/src/backend/utils/misc/guc-file.l
+++ b/src/backend/utils/misc/guc-file.l
@@ -4,7 +4,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v 1.2 2000/06/01 16:46:50 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc-file.l,v 1.3 2000/06/04 01:44:34 petere Exp $
*/
%{
@@ -22,6 +22,8 @@
#include "utils/elog.h"
#include "utils/guc.h"
+#define CONFIG_FILENAME "postgresql.conf"
+
static unsigned ConfigFileLineno;
enum {
@@ -41,6 +43,9 @@ enum {
#define YY_USER_INIT (ConfigFileLineno = 1)
#define YY_NO_UNPUT
+/* prototype, so compiler is happy with our high warnings setting */
+int GUC_yylex(void);
+
%}
SIGN ("-"|"+")
@@ -141,13 +146,13 @@ ProcessConfigFile(GucContext context)
/*
* Open file
*/
- filename = malloc(strlen(DataDir) + 16);
+ filename = malloc(strlen(DataDir) + strlen(CONFIG_FILENAME) + 2);
if (filename == NULL)
{
elog(elevel, "out of memory");
return;
}
- sprintf(filename, "%s/configuration", DataDir);
+ sprintf(filename, "%s/" CONFIG_FILENAME, DataDir);
fp = AllocateFile(filename, "r");
if (!fp)
@@ -155,7 +160,7 @@ ProcessConfigFile(GucContext context)
free(filename);
/* File not found is fine */
if (errno != ENOENT)
- elog(elevel, "could not read configuration: %s", strerror(errno));
+ elog(elevel, "could not read configuration file `" CONFIG_FILENAME "': %s", strerror(errno));
return;
}
@@ -166,7 +171,7 @@ ProcessConfigFile(GucContext context)
{
FreeFile(fp);
free(filename);
- elog(elevel, "could not stat configuration file: %s", strerror(errno));
+ elog(elevel, "could not stat configuration file `" CONFIG_FILENAME "': %s", strerror(errno));
return;
}
@@ -174,7 +179,7 @@ ProcessConfigFile(GucContext context)
{
FreeFile(fp);
free(filename);
- elog(elevel, "configuration file has wrong permissions");
+ elog(elevel, "configuration file `" CONFIG_FILENAME "' has wrong permissions");
return;
}
@@ -261,8 +266,7 @@ ProcessConfigFile(GucContext context)
FreeFile(fp);
free(filename);
free_name_value_list(head);
- elog(elevel, "%s:%u: syntax error (ps:%d, t:%d)", filename,
- ConfigFileLineno, parse_state, token);
+ elog(elevel, CONFIG_FILENAME ":%u: syntax error", ConfigFileLineno);
return;
out_of_memory:
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
new file mode 100644
index 00000000000..4fc286a4ee2
--- /dev/null
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -0,0 +1,20 @@
+#
+# PostgreSQL configuration file
+# -----------------------------
+#
+# This file consists of lines of the form
+#
+# name = value
+#
+# (The `=' is optional.) White space is collapsed, comments are
+# introduced by `#' anywhere on a line. The complete list of option
+# names and allowed values can be found in the PostgreSQL
+# documentation. Examples are:
+
+#log_connections = on
+#fsync = off
+#max_backends = 64
+
+# Any option can also be given as a command line switch to the
+# postmaster, e.g., `postmaster --log-connections=on'. Some options
+# can be set at run-time with the `SET' SQL command.
diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c
new file mode 100644
index 00000000000..edc82f35218
--- /dev/null
+++ b/src/backend/utils/misc/ps_status.c
@@ -0,0 +1,254 @@
+/*--------------------------------------------------------------------
+ * ps_status.c
+ *
+ * Routines to support changing the ps display of PostgreSQL backends
+ * to contain some useful information. Differs wildly across
+ * platforms.
+ *
+ * $Header: /cvsroot/pgsql/src/backend/utils/misc/ps_status.c,v 1.1 2000/06/04 01:44:34 petere Exp $
+ *
+ * Copyright 2000 by PostgreSQL Global Development Group
+ * various details abducted from various places
+ *--------------------------------------------------------------------
+ */
+
+#include "postgres.h"
+
+#include <unistd.h>
+
+
+#ifdef HAVE_SYS_PSTAT_H
+# include <sys/pstat.h> /* for HP-UX */
+#endif
+#ifdef HAVE_MACHINE_VMPARAM_H
+# include <machine/vmparam.h> /* for old BSD */
+#endif
+#ifdef HAVE_SYS_EXEC_H
+# include <sys/exec.h> /* for old BSD */
+#endif
+
+#include "miscadmin.h"
+
+#include "utils/ps_status.h"
+
+extern char **environ;
+
+
+/*------
+ * Alternative ways of updating ps display:
+ *
+ * PS_USE_SETPROCTITLE
+ * use the function setproctitle(const char *, ...)
+ * (newer BSD systems)
+ * PS_USE_PSTAT
+ * use the pstat(PSTAT_SETCMD, )
+ * (HPUX)
+ * PS_USE_PS_STRINGS
+ * assign PS_STRINGS->ps_argvstr = "string"
+ * (some BSD systems)
+ * PS_USE_CHANCE_ARGV
+ * assign argv[0] = "string"
+ * (some other BSD systems)
+ * PS_USE_CLOBBER_ARGV
+ * write over the argv and environment area
+ * (most SysV-like systems)
+ * PS_USE_NONE
+ * don't update ps display
+ * (This is the default, as it is safest.)
+ */
+#if defined(HAVE_SETPROCTITLE)
+# define PS_USE_SETPROCTITLE
+#elif defined(HAVE_PSTAT) && defined(PSTAT_SETCMD)
+# define PS_USE_PSTAT
+#elif defined(HAVE_PS_STRINGS)
+# define PS_USE_PS_STRINGS
+#elif defined(BSD) || defined(__bsdi__) || defined(__hurd__)
+# define PS_USE_CHANGE_ARGV
+#elif defined(__linux__) || defined(_AIX4) || defined(_AIX3) || defined(__sgi) || (defined(sun) && !defined(BSD)) || defined(ultrix) || defined(__ksr__) || defined(__osf__) || defined(__QNX__) || defined(__svr4__) || defined(__svr5__)
+# define PS_USE_CLOBBER_ARGV
+#else
+# define PS_USE_NONE
+#endif
+
+
+/* Different systems want the buffer padded differently */
+#if defined(_AIX3) || defined(__linux__) || defined(__QNX__) || defined(__svr4__)
+# define PS_PADDING '\0'
+#else
+# define PS_PADDING ' '
+#endif
+
+
+#ifndef PS_USE_CLOBBER_ARGV
+/* all but one options need a buffer to write their ps line in */
+#define PS_BUFFER_SIZE 256
+static char ps_buffer[PS_BUFFER_SIZE];
+static const size_t ps_buffer_size = PS_BUFFER_SIZE;
+
+#else /* PS_USE_CLOBBER_ARGV */
+static char * ps_buffer; /* will point to argv area */
+static size_t ps_buffer_size; /* space determined at run time */
+#endif /* PS_USE_CLOBBER_ARGV */
+
+static size_t ps_buffer_fixed_size; /* size of the constant prefix */
+
+
+
+/*
+ * Call this once at backend start.
+ */
+void
+init_ps_display(int argc, char *argv[],
+ const char * username, const char * dbname,
+ const char * host_info)
+{
+#ifndef PS_USE_NONE
+ Assert(username);
+ Assert(dbname);
+
+ /* no ps display for stand-alone backend */
+ if (!IsUnderPostmaster)
+ return;
+
+# ifdef PS_USE_CHANGE_ARGV
+ argv[0] = ps_buffer;
+ argv[1] = NULL;
+# endif /* PS_USE_CHANGE_ARGV */
+
+# ifdef PS_USE_CLOBBER_ARGV
+ /*
+ * If we're going to overwrite the argv area, count the space.
+ */
+ {
+ char * end_of_area = NULL;
+ char **new_environ;
+ int i;
+
+ /*
+ * 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]);
+
+ /*
+ * check for contiguous environ strings following argv
+ */
+ for (i = 0; end_of_area != NULL && environ[i] != NULL; i++)
+ if (end_of_area + 1 == environ[i])
+ end_of_area = environ[i] + strlen(environ[i]);
+
+ if (end_of_area == NULL)
+ {
+ ps_buffer = NULL;
+ ps_buffer_size = 0;
+ }
+ else
+ {
+ ps_buffer = argv[0];
+ ps_buffer_size = end_of_area - argv[0] - 1;
+ }
+ argv[1] = NULL;
+
+ /*
+ * move the environment out of the way
+ */
+ for (i = 0; environ[i] != NULL; i++)
+ ;
+ new_environ = malloc(sizeof (char *) * (i + 1));
+ for (i = 0; environ[i] != NULL; i++)
+ new_environ[i] = strdup(environ[i]);
+ new_environ[i] = NULL;
+ environ = new_environ;
+ }
+# endif /* PS_USE_CLOBBER_ARGV */
+
+ /*
+ * Make fixed prefix
+ */
+# ifdef PS_USE_SETPROCTITLE
+ /* apparently setproctitle() already adds a `progname:' prefix to
+ * the ps line */
+ snprintf(ps_buffer, ps_buffer_size,
+ "%s %s %s ",
+ username, dbname, host_info);
+# else
+ snprintf(ps_buffer, ps_buffer_size,
+ "postgres: %s %s %s ",
+ username, dbname, host_info);
+# endif
+
+ ps_buffer_fixed_size = strlen(ps_buffer);
+#endif /* not PS_USE_NONE */
+}
+
+
+
+/*
+ * Call this to update the ps status display to a fixed prefix plus an
+ * indication of what you're currently doing passed in the argument.
+ */
+void
+set_ps_display(const char * value)
+{
+ /* no ps display for stand-alone backend */
+ if (!IsUnderPostmaster)
+ return;
+
+#ifndef PS_USE_NONE
+ if (!ps_buffer)
+ return;
+# ifdef PS_USE_SETPROCTITLE
+ setproctitle("%s%s", ps_buffer, value);
+
+# else /* not PS_USE_SETPROCTITLE */
+ {
+ size_t vallen = strlen(value);
+
+ strncpy(ps_buffer + ps_buffer_fixed_size, value,
+ ps_buffer_size - ps_buffer_fixed_size);
+
+ if (ps_buffer_fixed_size + vallen >= ps_buffer_size)
+ ps_buffer[ps_buffer_size - 1] = 0;
+ else
+ ps_buffer[ps_buffer_fixed_size + vallen] = 0;
+
+# ifdef PS_USE_PSTAT
+ {
+ union pstun pst;
+
+ pst.pst_command = ps_buffer;
+ pstat(PSTAT_SETCMD, pst, strlen(ps_buffer), 0, 0);
+ }
+# endif /* PS_USE_PSTAT */
+
+# ifdef PS_USE_PS_STRINGS
+ PS_STRINGS->ps_nargvstr = 1;
+ PS_STRINGS->ps_argvstr = ps_buffer;
+# endif /* PS_USE_PS_STRINGS */
+
+# ifdef PS_USE_CLOBBER_ARGV
+ {
+ char * cp;
+ /* pad unused memory */
+ for(cp = ps_buffer + ps_buffer_fixed_size + vallen;
+ cp < ps_buffer + ps_buffer_size;
+ cp++)
+ *cp = PS_PADDING;
+ }
+# endif /* PS_USE_CLOBBER_ARGV */
+ }
+# endif /* not USE_SETPROCTITLE */
+#endif /* not PS_USE_NONE */
+}
+
+
+/*
+ * Returns what's currently in the ps display, in case someone needs
+ * it.
+ */
+const char *
+get_ps_display(void)
+{
+ return ps_buffer + ps_buffer_fixed_size;
+}