Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5e2b99d

Browse files
committed
Avoid assuming that type key_t is 32 bits, since it reportedly isn't
on 64-bit Solaris. Use a non-system-dependent datatype for UsedShmemSegID, namely unsigned long (which we were already assuming could hold a shmem key anyway, cf RecordSharedMemoryInLockFile).
1 parent 35ddc2e commit 5e2b99d

File tree

6 files changed

+31
-25
lines changed

6 files changed

+31
-25
lines changed

src/backend/bootstrap/bootstrap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.168 2003/11/29 19:51:41 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.169 2003/12/01 22:15:37 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -290,7 +290,9 @@ BootstrapMain(int argc, char *argv[])
290290
#ifdef EXEC_BACKEND
291291
char *p;
292292

293-
sscanf(optarg, "%d,%p,", &UsedShmemSegID, &UsedShmemSegAddr);
293+
sscanf(optarg, "%lu,%p,",
294+
&UsedShmemSegID,
295+
&UsedShmemSegAddr);
294296
p = strchr(optarg, ',');
295297
if (p)
296298
p = strchr(p + 1, ',');

src/backend/port/sysv_sema.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/port/sysv_sema.c,v 1.11 2003/11/29 19:51:54 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/port/sysv_sema.c,v 1.12 2003/12/01 22:15:37 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -42,7 +42,7 @@ union semun
4242
};
4343
#endif
4444

45-
typedef uint32 IpcSemaphoreKey; /* semaphore key passed to semget(2) */
45+
typedef key_t IpcSemaphoreKey; /* semaphore key passed to semget(2) */
4646
typedef int IpcSemaphoreId; /* semaphore ID returned by semget(2) */
4747

4848
/*
@@ -115,8 +115,8 @@ InternalIpcSemaphoreCreate(IpcSemaphoreKey semKey, int numSems)
115115
*/
116116
ereport(FATAL,
117117
(errmsg("could not create semaphores: %m"),
118-
errdetail("Failed system call was semget(%d, %d, 0%o).",
119-
(int) semKey, numSems,
118+
errdetail("Failed system call was semget(%lu, %d, 0%o).",
119+
(unsigned long) semKey, numSems,
120120
IPC_CREAT | IPC_EXCL | IPCProtection),
121121
(errno == ENOSPC) ?
122122
errhint("This error does *not* mean that you have run out of disk space.\n"

src/backend/port/sysv_shmem.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/port/sysv_shmem.c,v 1.26 2003/11/29 19:51:54 pgsql Exp $
13+
* $PostgreSQL: pgsql/src/backend/port/sysv_shmem.c,v 1.27 2003/12/01 22:15:37 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -34,12 +34,14 @@
3434
#include "storage/ipc.h"
3535
#include "storage/pg_shmem.h"
3636

37+
38+
typedef key_t IpcMemoryKey; /* shared memory key passed to shmget(2) */
3739
typedef int IpcMemoryId; /* shared memory ID returned by shmget(2) */
3840

3941
#define IPCProtection (0600) /* access/modify by user only */
4042

4143

42-
IpcMemoryKey UsedShmemSegID = 0;
44+
unsigned long UsedShmemSegID = 0;
4345
void *UsedShmemSegAddr = NULL;
4446

4547
static void *InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size);
@@ -90,8 +92,8 @@ InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size)
9092
*/
9193
ereport(FATAL,
9294
(errmsg("could not create shared memory segment: %m"),
93-
errdetail("Failed system call was shmget(key=%d, size=%u, 0%o).",
94-
(int) memKey, size,
95+
errdetail("Failed system call was shmget(key=%lu, size=%u, 0%o).",
96+
(unsigned long) memKey, size,
9597
IPC_CREAT | IPC_EXCL | IPCProtection),
9698
(errno == EINVAL) ?
9799
errhint("This error usually means that PostgreSQL's request for a shared memory "
@@ -247,9 +249,10 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port)
247249
/* If Exec case, just attach and return the pointer */
248250
if (ExecBackend && UsedShmemSegAddr != NULL && !makePrivate)
249251
{
250-
if ((hdr = PGSharedMemoryAttach(UsedShmemSegID, &shmid)) == NULL)
251-
elog(FATAL, "could not attach to proper memory at fixed address: shmget(key=%d, addr=%p) failed: %m",
252-
(int) UsedShmemSegID, UsedShmemSegAddr);
252+
hdr = PGSharedMemoryAttach((IpcMemoryKey) UsedShmemSegID, &shmid);
253+
if (hdr == NULL)
254+
elog(FATAL, "could not attach to proper memory at fixed address: shmget(key=%lu, addr=%p) failed: %m",
255+
UsedShmemSegID, UsedShmemSegAddr);
253256
return hdr;
254257
}
255258

@@ -331,7 +334,7 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port)
331334

332335
/* Save info for possible future use */
333336
UsedShmemSegAddr = memAddress;
334-
UsedShmemSegID = NextShmemSegID;
337+
UsedShmemSegID = (unsigned long) NextShmemSegID;
335338

336339
return hdr;
337340
}

src/backend/postmaster/postmaster.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.350 2003/11/29 19:51:55 pgsql Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.351 2003/12/01 22:15:37 tgl Exp $
4141
*
4242
* NOTES
4343
*
@@ -2558,8 +2558,10 @@ BackendFork(Port *port)
25582558
#ifdef EXEC_BACKEND
25592559
Assert(UsedShmemSegID != 0 && UsedShmemSegAddr != NULL);
25602560
/* database name at the end because it might contain commas */
2561-
snprintf(pbuf, NAMEDATALEN + 256, "%d,%d,%d,%p,%s", port->sock, canAcceptConnections(),
2562-
UsedShmemSegID, UsedShmemSegAddr, port->database_name);
2561+
snprintf(pbuf, sizeof(pbuf), "%d,%d,%lu,%p,%s",
2562+
port->sock, canAcceptConnections(),
2563+
UsedShmemSegID, UsedShmemSegAddr,
2564+
port->database_name);
25632565
av[ac++] = pbuf;
25642566
#else
25652567
av[ac++] = port->database_name;
@@ -2902,8 +2904,8 @@ SSDataBase(int xlop)
29022904
#ifdef EXEC_BACKEND
29032905
Assert(UsedShmemSegID != 0 && UsedShmemSegAddr != NULL);
29042906
/* database name at the end because it might contain commas */
2905-
snprintf(pbuf, NAMEDATALEN + 256, "%d,%p,%s", UsedShmemSegID,
2906-
UsedShmemSegAddr, "template1");
2907+
snprintf(pbuf, sizeof(pbuf), "%lu,%p,%s",
2908+
UsedShmemSegID, UsedShmemSegAddr, "template1");
29072909
av[ac++] = pbuf;
29082910
#else
29092911
av[ac++] = "template1";

src/backend/tcop/postgres.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.378 2003/11/29 21:40:43 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.379 2003/12/01 22:15:37 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -2282,7 +2282,8 @@ PostgresMain(int argc, char *argv[], const char *username)
22822282
* global or static,
22832283
* when fork */
22842284

2285-
sscanf(optarg, "%d,%d,%d,%p,", &MyProcPort->sock, &PMcanAcceptConnections,
2285+
sscanf(optarg, "%d,%d,%lu,%p,",
2286+
&MyProcPort->sock, &PMcanAcceptConnections,
22862287
&UsedShmemSegID, &UsedShmemSegAddr);
22872288
/* Grab dbname as last param */
22882289
for (i = 0, p = optarg - 1; i < 4 && p; i++)

src/include/storage/pg_shmem.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
1818
* Portions Copyright (c) 1994, Regents of the University of California
1919
*
20-
* $PostgreSQL: pgsql/src/include/storage/pg_shmem.h,v 1.9 2003/11/29 22:41:13 pgsql Exp $
20+
* $PostgreSQL: pgsql/src/include/storage/pg_shmem.h,v 1.10 2003/12/01 22:15:38 tgl Exp $
2121
*
2222
*-------------------------------------------------------------------------
2323
*/
2424
#ifndef PG_SHMEM_H
2525
#define PG_SHMEM_H
2626

27-
typedef uint32 IpcMemoryKey; /* shared memory key passed to shmget(2) */
28-
2927
typedef struct PGShmemHeader /* standard header for all Postgres shmem */
3028
{
3129
int32 magic; /* magic # to identify Postgres segments */
@@ -37,7 +35,7 @@ typedef struct PGShmemHeader /* standard header for all Postgres shmem */
3735

3836

3937
#ifdef EXEC_BACKEND
40-
extern IpcMemoryKey UsedShmemSegID;
38+
extern unsigned long UsedShmemSegID;
4139
extern void *UsedShmemSegAddr;
4240
#endif
4341

0 commit comments

Comments
 (0)