summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorBruce Momjian2001-05-24 15:53:34 +0000
committerBruce Momjian2001-05-24 15:53:34 +0000
commitf36fc7bb63addb9254e6d0db77e511841eba8de8 (patch)
tree6eb786ca46c5e2dc585bdf66e10e751f7b784f8a /src/backend
parent6f101c806b11af05ab9d775efa2012d497375ba0 (diff)
I haven't tried building postgres with the Watcom compiler for 7.1 because
it does not support 64bit integers. AFAIK that's the default data type for OIDs, so I am not surprised that this does not work. Use gcc instead. BTW., 7.1 does not compile as is with gcc either, I believed the required patches made it into the 7.1.1 release but obviously I missed the deadline. Since the ports mailing list does not seem to be archived I have attached a copy of the patch (for 7.1 and 7.1.1). I've just performed a build of a Watcom compiled version and found a couple of bugs in the watcom specific part of that patch. Please use the attached version instead. Tegge, Bernd
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/Makefile5
-rw-r--r--src/backend/port/qnx4/sem.c41
-rw-r--r--src/backend/port/qnx4/shm.c61
-rw-r--r--src/backend/port/qnx4/tstsem.c6
4 files changed, 96 insertions, 17 deletions
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 30ea30f8d75..4db21fe665c 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -4,7 +4,7 @@
#
# Copyright (c) 1994, Regents of the University of California
#
-# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.71 2001/04/23 20:27:55 petere Exp $
+# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.72 2001/05/24 15:53:32 momjian Exp $
#
#-------------------------------------------------------------------------
@@ -25,7 +25,8 @@ OBJS := $(DIRS:%=%/SUBSYS.o)
ifeq ($(PORTNAME), qnx4)
# This file crashes qnx4's wlink and is therefore not in
# bootstrap/SUBSYS.o on that platform. (Wotta hack ... is it still
-# necessary?)
+# necessary?) [ Yes, until the Watcom compiler goes open source it's
+# effectively unsupported ]
OBJS+= bootstrap/bootstrap.o
endif
diff --git a/src/backend/port/qnx4/sem.c b/src/backend/port/qnx4/sem.c
index f339e16973a..188a5f0616f 100644
--- a/src/backend/port/qnx4/sem.c
+++ b/src/backend/port/qnx4/sem.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/port/qnx4/Attic/sem.c,v 1.4 2001/02/02 18:21:58 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/port/qnx4/Attic/sem.c,v 1.5 2001/05/24 15:53:33 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -23,14 +23,16 @@
#include "storage/ipc.h"
#include "storage/proc.h"
#include <sys/sem.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
-#define SETMAX ((MAXBACKENDS + PROC_NSEMS_PER_SET - 1) / PROC_NSEMS_PER_SET)
+#define SETMAX ((MAXBACKENDS + PROC_NSEMS_PER_SET + 1) / PROC_NSEMS_PER_SET)
#define SEMMAX (PROC_NSEMS_PER_SET+1)
#define OPMAX 8
#define MODE 0700
-#define SHM_INFO_NAME "SysV_Sem_Info"
+#define SHM_INFO_NAME "PgSysV_Sem_Info"
struct pending_ops
@@ -56,6 +58,17 @@ struct sem_info
static struct sem_info *SemInfo = (struct sem_info *) - 1;
+/* ----------------------------------------------------------------
+ * semclean - remove the shared memory file on exit
+ * only called by the process which created the shm file
+ * ----------------------------------------------------------------
+ */
+
+static void
+semclean( void )
+{
+ remove( "/dev/shmem/" SHM_INFO_NAME );
+}
int
semctl(int semid, int semnum, int cmd, /* ... */ union semun arg)
@@ -132,6 +145,7 @@ semget(key_t key, int nsems, int semflg)
semid,
semnum /* , semnum1 */ ;
int exist = 0;
+ struct stat statbuf;
if (nsems < 0 || nsems > SEMMAX)
{
@@ -153,6 +167,26 @@ semget(key_t key, int nsems, int semflg)
return fd;
/* The size may only be set once. Ignore errors. */
ltrunc(fd, sizeof(struct sem_info), SEEK_SET);
+ if ( fstat( fd, &statbuf ) ) /* would be strange : the only doc'ed */
+ { /* error is EBADF */
+ close( fd );
+ return -1;
+ }
+ /*
+ * size is rounded by proc to the next __PAGESIZE
+ */
+ if ( statbuf.st_size !=
+ ((( sizeof(struct sem_info) /__PAGESIZE)+1) * __PAGESIZE) )
+ {
+ fprintf( stderr,
+ "Found a pre-existing shared memory block for the semaphore memory\n"
+ "of a different size (%ld instead %ld). Make sure that all executables\n"
+ "are from the same release or remove the file \"/dev/shmem/%s\"\n"
+ "left by a previous version.\n", statbuf.st_size,
+ sizeof(struct sem_info), SHM_INFO_NAME);
+ errno = EACCES;
+ return -1;
+ }
SemInfo = mmap(NULL, sizeof(struct sem_info),
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (SemInfo == MAP_FAILED)
@@ -167,6 +201,7 @@ semget(key_t key, int nsems, int semflg)
for (semid = 0; semid < SETMAX; semid++)
SemInfo->set[semid].key = -1;
sem_post(&SemInfo->sem);
+ on_proc_exit( semclean, NULL );
}
}
diff --git a/src/backend/port/qnx4/shm.c b/src/backend/port/qnx4/shm.c
index 14c77f4fc9c..b96203f1c2d 100644
--- a/src/backend/port/qnx4/shm.c
+++ b/src/backend/port/qnx4/shm.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/port/qnx4/Attic/shm.c,v 1.4 2001/03/22 03:59:43 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/port/qnx4/Attic/shm.c,v 1.5 2001/05/24 15:53:33 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -15,9 +15,11 @@
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/shm.h>
+#include <sys/stat.h>
#define MODE 0777
@@ -41,6 +43,12 @@ static int shm_updinfo(int i, struct shm_info * info);
static int shm_getinfo(int shmid, struct shm_info * info);
static int shm_getinfobyaddr(const void *addr, struct shm_info * info);
+static char *
+keytoname(key_t key, char *name)
+{
+ sprintf( name,"PgShm%x", key );
+ return name;
+}
static int
shm_putinfo(struct shm_info * info)
@@ -172,25 +180,51 @@ shmctl(int shmid, int cmd, struct shmid_ds * buf)
{
struct shm_info info;
char name[NAME_MAX + 1];
+ int result;
+ int fd;
+ struct stat statbuf;
- if (cmd == IPC_RMID)
+
+ switch( cmd )
{
+ case IPC_RMID :
if (shm_getinfo(shmid, &info) == -1)
{
errno = EACCES;
return -1;
}
- return shm_unlink(itoa(info.key, name, 16));
+ close( info.shmid );
+ keytoname(info.key, name);
+ return shm_unlink( name );
+
+ case IPC_STAT :
+ /*
+ * we have to open it first. stat() does no prefix tracking
+ * -> the call would go to fsys instead of proc
+ */
+ keytoname(shmid, name);
+ fd = shm_open( name, 0, MODE );
+ if ( fd >= 0 )
+ {
+ result = fstat( fd, &statbuf );
+ /*
+ * if the file exists, subtract 2 from linkcount :
+ * one for our own open and one for the dir entry
+ */
+ if ( ! result )
+ buf->shm_nattch = statbuf.st_nlink-2;
+ close( fd );
+ return result;
}
- if (cmd == IPC_STAT)
+ else
{
-
/*
- * Can we support IPC_STAT? We only need shm_nattch ... For now,
- * punt and assume the shm seg does not exist.
+ * if there's no entry for this key it doesn't matter
+ * the next shmget() would get a different shm anyway
*/
- errno = EINVAL;
- return -1;
+ buf->shm_nattch = 0;
+ return 0;
+ }
}
errno = EINVAL;
return -1;
@@ -214,7 +248,7 @@ shmget(key_t key, size_t size, int flags)
else
oflag |= O_RDONLY;
}
- info.shmid = shm_open(itoa(key, name, 16), oflag, MODE);
+ info.shmid = shm_open(keytoname(key, name), oflag, MODE);
/* store shared memory information */
if (info.shmid != -1)
@@ -222,8 +256,13 @@ shmget(key_t key, size_t size, int flags)
info.key = key;
info.size = size;
info.addr = NULL;
- if (shm_putinfo(&info) == -1)
+ if (shm_putinfo(&info) == -1) {
+ close( info.shmid );
+ if ( (oflag & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL) ) {
+ shm_unlink( name );
+ }
return -1;
+ }
}
/* The size may only be set once. Ignore errors. */
diff --git a/src/backend/port/qnx4/tstsem.c b/src/backend/port/qnx4/tstsem.c
index dc697ceaed5..c58a724f9d0 100644
--- a/src/backend/port/qnx4/tstsem.c
+++ b/src/backend/port/qnx4/tstsem.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/port/qnx4/Attic/tstsem.c,v 1.3 2000/04/12 17:15:30 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/port/qnx4/Attic/tstsem.c,v 1.4 2001/05/24 15:53:33 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -40,6 +40,10 @@ sig_handler(int sig_no)
printf("semval = %d\n", i);
}
+void on_proc_exit( void (*function)(), Datum arg )
+{
+ atexit( function );
+}
int
main(int argc, char **argv)
{