aboutsummaryrefslogtreecommitdiff
path: root/src/backend/port/sysv_shmem.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/port/sysv_shmem.c')
-rw-r--r--src/backend/port/sysv_shmem.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c
index 18b4a193f3f..02847698e60 100644
--- a/src/backend/port/sysv_shmem.c
+++ b/src/backend/port/sysv_shmem.c
@@ -10,7 +10,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/port/sysv_shmem.c,v 1.29 2004/01/27 00:45:26 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/port/sysv_shmem.c,v 1.30 2004/02/02 00:11:31 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -140,8 +140,13 @@ InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size)
/* use intimate shared memory on Solaris */
memAddress = shmat(shmid, 0, SHM_SHARE_MMU);
#else
+
+#ifdef EXEC_BACKEND
+ memAddress = shmat(shmid, UsedShmemSegAddr, 0);
+#else
memAddress = shmat(shmid, 0, 0);
#endif
+#endif
if (memAddress == (void *) -1)
elog(FATAL, "shmat(id=%d) failed: %m", shmid);
@@ -244,18 +249,32 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port)
PGShmemHeader *hdr;
IpcMemoryId shmid;
- /* Room for a header? */
- Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
-
+#ifdef EXEC_BACKEND
/* If Exec case, just attach and return the pointer */
- if (ExecBackend && UsedShmemSegAddr != NULL && !makePrivate)
+ if (UsedShmemSegAddr != NULL && !makePrivate)
{
+ void* origUsedShmemSegAddr = UsedShmemSegAddr;
+
+#ifdef CYGWIN
+ /* cygipc (currently) appears to not detach on exec. */
+ PGSharedMemoryDetach();
+ UsedShmemSegAddr = origUsedShmemSegAddr;
+#endif
+ elog(DEBUG3,"Attaching to %x",UsedShmemSegAddr);
hdr = PGSharedMemoryAttach((IpcMemoryKey) UsedShmemSegID, &shmid);
if (hdr == NULL)
- elog(FATAL, "could not attach to proper memory at fixed address: shmget(key=%lu, addr=%p) failed: %m",
- UsedShmemSegID, UsedShmemSegAddr);
+ elog(FATAL, "could not attach to proper memory at fixed address: shmget(key=%d, addr=%p) failed: %m",
+ (int) UsedShmemSegID, UsedShmemSegAddr);
+ if (hdr != origUsedShmemSegAddr)
+ elog(FATAL,"attaching to shared mem returned unexpected address (got %p, expected %p)",
+ hdr,UsedShmemSegAddr);
+ UsedShmemSegAddr = hdr;
return hdr;
}
+#endif
+
+ /* Room for a header? */
+ Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
/* Make sure PGSharedMemoryAttach doesn't fail without need */
UsedShmemSegAddr = NULL;
@@ -354,12 +373,18 @@ PGSharedMemoryDetach(void)
{
if (UsedShmemSegAddr != NULL)
{
- if (shmdt(UsedShmemSegAddr) < 0)
+ if ((shmdt(UsedShmemSegAddr) < 0)
+#if (defined(EXEC_BACKEND) && defined(CYGWIN))
+ /* Work-around for cygipc exec bug */
+ && shmdt(NULL) < 0
+#endif
+ )
elog(LOG, "shmdt(%p) failed: %m", UsedShmemSegAddr);
UsedShmemSegAddr = NULL;
}
}
+
/*
* Attach to shared memory and make sure it has a Postgres header
*