fork/exec.
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.154 2003/05/06 05:15:45 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.155 2003/05/06 23:34:55 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "miscadmin.h"
#include "storage/freespace.h"
#include "storage/ipc.h"
+#include "storage/pg_shmem.h"
#include "storage/proc.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
* variable */
}
- while ((flag = getopt(argc, argv, "B:d:D:Fo:px:")) != -1)
+ while ((flag = getopt(argc, argv, "B:d:D:Fo:p:x:")) != -1)
{
switch (flag)
{
xlogop = atoi(optarg);
break;
case 'p':
+ {
/* indicates fork from postmaster */
+ char *p;
+#ifdef EXEC_BACKEND
+ sscanf(optarg, "%d,", &UsedShmemSegID);
+ p = strchr(optarg, ',');
+ if (p)
+ dbname = strdup(p+1);
+#else
+ dbname = strdup(optarg);
+#endif
break;
+ }
case 'B':
SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
break;
usage();
break;
}
- } /* while */
+ }
- if (argc - optind != 1)
+ if (!dbname && argc - optind == 1)
+ {
+ dbname = argv[optind];
+ optind++;
+ }
+ if (!dbname || argc != optind)
usage();
- dbname = argv[optind];
-
- Assert(dbname);
if (IsUnderPostmaster && ExecBackend && MyProc /* ordinary backend */)
{
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/port/sysv_shmem.c,v 1.7 2003/04/24 21:24:36 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/port/sysv_shmem.c,v 1.8 2003/05/06 23:34:55 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "storage/ipc.h"
#include "storage/pg_shmem.h"
-
-typedef uint32 IpcMemoryKey; /* shared memory key passed to shmget(2) */
typedef int IpcMemoryId; /* shared memory ID returned by shmget(2) */
#define IPCProtection (0600) /* access/modify by user only */
+#ifdef EXEC_BACKEND
+IpcMemoryKey UsedShmemSegID = 0;
+#endif
+
static void *InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size);
static void IpcMemoryDetach(int status, Datum shmaddr);
static void IpcMemoryDelete(int status, Datum shmId);
/* Room for a header? */
Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
- /* Loop till we find a free IPC key */
- NextShmemSegID = port * 1000;
+#ifdef EXEC_BACKEND
+ if (UsedShmemSegID != 0)
+ NextShmemSegID = UsedShmemSegID;
+ else
+#endif
+ NextShmemSegID = port * 1000 + 1;
- for (NextShmemSegID++;; NextShmemSegID++)
+ for (;;NextShmemSegID++)
{
IpcMemoryId shmid;
hdr->totalsize = size;
hdr->freeoffset = MAXALIGN(sizeof(PGShmemHeader));
+#ifdef EXEC_BACKEND
+ if (!makePrivate && UsedShmemSegID == 0)
+ UsedShmemSegID = NextShmemSegID;
+#endif
+
return hdr;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.321 2003/05/03 05:13:18 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.322 2003/05/06 23:34:55 momjian Exp $
*
* NOTES
*
#include "nodes/nodes.h"
#include "storage/fd.h"
#include "storage/ipc.h"
+#include "storage/pg_shmem.h"
#include "storage/pmsignal.h"
#include "storage/proc.h"
#include "access/xlog.h"
int ac;
char debugbuf[32];
char protobuf[32];
+#ifdef EXEC_BACKEND
+ char pbuf[NAMEDATALEN + 256];
+#endif
int i;
int status;
struct timeval now;
* database to use. -p marks the end of secure switches.
*/
av[ac++] = "-p";
+#ifdef EXEC_BACKEND
+ Assert(UsedShmemSegID != 0);
+ /* database name at the end because it might contain commas */
+ snprintf(pbuf, NAMEDATALEN + 256, "%d,%d,%s", port->sock, UsedShmemSegID, port->database_name);
+ av[ac++] = pbuf;
+#else
av[ac++] = port->database_name;
-
+#endif
/*
* Pass the (insecure) option switches from the connection request.
* (It's OK to mangle port->cmdline_options now.)
int ac = 0;
char nbbuf[32];
char xlbuf[32];
+#ifdef EXEC_BACKEND
+ char pbuf[NAMEDATALEN + 256];
+#endif
#ifdef LINUX_PROFILE
setitimer(ITIMER_PROF, &prof_itimer, NULL);
av[ac++] = xlbuf;
av[ac++] = "-p";
+#ifdef EXEC_BACKEND
+ Assert(UsedShmemSegID != 0);
+ /* database name at the end because it might contain commas */
+ snprintf(pbuf, NAMEDATALEN + 256, "%d,%s", UsedShmemSegID, "template1");
+ av[ac++] = pbuf;
+#else
av[ac++] = "template1";
+#endif
av[ac] = (char *) NULL;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.67 2002/09/04 20:31:25 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.68 2003/05/06 23:34:55 momjian Exp $
*
*-------------------------------------------------------------------------
*/
hash_search(ShmemIndex, (void *) &item, HASH_REMOVE, NULL);
LWLockRelease(ShmemIndexLock);
- elog(WARNING, "ShmemInitStruct: cannot allocate '%s'",
- name);
+ elog(WARNING, "ShmemInitStruct: cannot allocate '%s'", name);
*foundPtr = FALSE;
return NULL;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.337 2003/05/06 21:51:41 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.338 2003/05/06 23:34:55 momjian Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
#include "rewrite/rewriteHandler.h"
#include "storage/freespace.h"
#include "storage/ipc.h"
+#include "storage/pg_shmem.h"
#include "storage/proc.h"
#include "tcop/fastpath.h"
#include "tcop/pquery.h"
*/
if (secure)
{
+ char *p;
+#ifdef EXEC_BACKEND
+ sscanf(optarg, "%d,%d,", &MyProcPort->sock, &UsedShmemSegID);
+ /* Grab dbname as last param */
+ p = strchr(optarg, ',');
+ if (p)
+ p = strchr(p+1, ',');
+ if (p)
+ dbname = strdup(p+1);
+#else
dbname = strdup(optarg);
+#endif
secure = false; /* subsequent switches are NOT
* secure */
ctx = PGC_BACKEND;
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
- puts("$Revision: 1.337 $ $Date: 2003/05/06 21:51:41 $\n");
+ puts("$Revision: 1.338 $ $Date: 2003/05/06 23:34:55 $\n");
}
/*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: pg_shmem.h,v 1.4 2002/09/04 20:31:45 momjian Exp $
+ * $Id: pg_shmem.h,v 1.5 2003/05/06 23:34:56 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PG_SHMEM_H
#define PG_SHMEM_H
+typedef uint32 IpcMemoryKey; /* shared memory key passed to shmget(2) */
+
typedef struct PGShmemHeader /* standard header for all Postgres shmem */
{
int32 magic; /* magic # to identify Postgres segments */
} PGShmemHeader;
+#ifdef EXEC_BACKEND
+extern IpcMemoryKey UsedShmemSegID;
+#endif
+
extern PGShmemHeader *PGSharedMemoryCreate(uint32 size, bool makePrivate,
int port);
extern bool PGSharedMemoryIsInUse(unsigned long id1, unsigned long id2);