From 1f159e562b2a31234edba781218ce5278ea2cfd8 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Mon, 18 Dec 2000 18:45:05 +0000 Subject: [PATCH] >> Here is a patch for the beos port (All regression tests are OK). >> xlog.c : special case for beos to avoid 'link' which does not work yet >> beos/sem.c : implementation of new sem_ctl call (GETPID) and a new >sem_op >> flag (IPCNOWAIT) >> dynloader/beos.c : add a verification of symbol validity (seem that the >> loader sometime return OK with an invalid symbol) >> postmaster.c : add beos forking support for the new checkpoint process >> postgres.c : remove beos special case for getrusage >> beos.h : Correction of a bas definition of AF_UNIX, misc defnitions >> >> >> thanks >> >> >> cyril Cyril VELTER --- src/backend/access/transam/xlog.c | 6 +- src/backend/port/beos/sem.c | 89 +++++++++++++++++++++++------ src/backend/port/dynloader/beos.c | 7 ++- src/backend/postmaster/postmaster.c | 17 +++++- src/backend/tcop/postgres.c | 6 +- src/include/port/beos.h | 10 +++- 6 files changed, 110 insertions(+), 25 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index ba85f4b60d..f39e279a72 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1994, Regents of the University of California * - * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.43 2000/12/18 00:44:45 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.44 2000/12/18 18:45:03 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -874,7 +874,11 @@ XLogFileInit(uint32 log, uint32 seg, bool *usexistent) close(fd); +#ifndef __BEOS__ if (link(tpath, path) < 0) +#else + if (rename(tpath, path) < 0) +#endif elog(STOP, "InitRelink(logfile %u seg %u) failed: %m", logId, logSeg); diff --git a/src/backend/port/beos/sem.c b/src/backend/port/beos/sem.c index d26369b3ee..1a6d0d97a1 100644 --- a/src/backend/port/beos/sem.c +++ b/src/backend/port/beos/sem.c @@ -12,9 +12,20 @@ #include "postgres.h" #include #include +#include #include #include "utils/elog.h" +/*#define TDBG*/ +#ifdef TDBG +#define TRACEDBG(x) printf(x);printf("\n") +#define TRACEDBGP(x,y) printf(x,y);printf("\n") +#define TRACEDBGPP(x,y,z) printf(x,y,z);printf("\n") +#else +#define TRACEDBG(x) +#define TRACEDBGP(x,y) +#define TRACEDBGPP(x,y,z) +#endif /* Control of a semaphore pool. The pool is an area in which we stored all the semIds of the pool. The first 4 bytes are the number of semaphore allocated @@ -25,16 +36,19 @@ int semctl(int semId,int semNum,int flag,union semun semun) int32* Address; area_info info; + TRACEDBG("->semctl"); /* Try to find the pool */ if (get_area_info(semId,&info)!=B_OK) { /* pool is invalid (BeOS area id is invalid) */ errno=EINVAL; + TRACEDBG("<-semctl invalid pool"); return -1; } /* Get the pool address */ Address=(int32*)info.address; + TRACEDBGP("--semctl address %d",Address); /* semNum might be 0 */ @@ -44,18 +58,22 @@ int semctl(int semId,int semNum,int flag,union semun semun) if (flag==SETALL) { long i; + TRACEDBG("--semctl setall"); for (i=0;i 0) - while(acquire_sem_etc(Address[i+1],cnt,0,0)==B_INTERRUPTED); + while(acquire_sem_etc(Address[2*i+1],cnt,0,0)==B_INTERRUPTED); if (cnt < 0) - release_sem_etc(Address[i+1],-cnt,0); + release_sem_etc(Address[2*i+1],-cnt,0); } return 1; } @@ -64,37 +82,49 @@ int semctl(int semId,int semNum,int flag,union semun semun) if (flag==SETVAL) { int32 cnt; + TRACEDBGP("--semctl setval %d",semun.val); /* Get the current count */ - get_sem_count(Address[semNum+1],&cnt); + get_sem_count(Address[2*semNum+1],&cnt); /* Compute and set the new count (relative to the old one) */ cnt-=semun.val; + TRACEDBGPP("--semctl acquire id : %d cnt : %d",Address[2*semNum+1],cnt); if (cnt > 0) - while(acquire_sem_etc(Address[semNum+1],cnt,0,0)==B_INTERRUPTED); + while(acquire_sem_etc(Address[2*semNum+1],cnt,0,0)==B_INTERRUPTED); if (cnt < 0) - release_sem_etc(Address[semNum+1],-cnt,0); + release_sem_etc(Address[2*semNum+1],-cnt,0); return 1; } + /* Get the last pid which accesed the sem */ + if (flag==GETPID) + { + TRACEDBG("->semctl getpid"); + return Address[2*semNum+2]; + } + /* Delete the pool */ if (flag==IPC_RMID) { long i; thread_info ti; + TRACEDBG("->semctl rmid"); get_thread_info(find_thread(NULL),&ti); /* Loop over all semaphore to delete them */ + TRACEDBGP("->semctl nmbre %d",Address[0]); for (i=0;isemctl id %d",Address[2*i+1]); + set_sem_owner(Address[2*i+1],ti.team); /* Delete the semaphore */ - delete_sem(Address[i+1]); + delete_sem(Address[2*i+1]); /* Reset to an invalid semId (in case other process try to get the infos from a cloned area */ - Address[i+1]=0; + Address[2*i+1]=0; } /* Set the semaphore count to 0 */ @@ -111,6 +141,7 @@ int semctl(int semId,int semNum,int flag,union semun semun) if (flag==GETNCNT) { /* TO BE IMPLEMENTED */ + TRACEDBG("--semctl getncnt"); elog(ERROR,"beos : semctl error : GETNCNT not implemented"); return 0; } @@ -119,12 +150,15 @@ int semctl(int semId,int semNum,int flag,union semun semun) if (flag==GETVAL) { int32 cnt; - get_sem_count(Address[semNum+1],&cnt); + TRACEDBG("--semctl getval"); + get_sem_count(Address[2*semNum+1],&cnt); + TRACEDBGP("--semctl val %d",cnt); return cnt; } elog(ERROR,"beos : semctl error : unknown flag"); + TRACEDBG("<-semctl unknown flag"); return 0; } @@ -135,6 +169,7 @@ int semget(int semKey, int semNum, int flags) area_id parea; void* Address; + TRACEDBGPP("->semget key : %d num : %d",semKey,semNum); /* Name of the area to find */ sprintf(Nom,"SYSV_IPC_SEM : %d",semKey); @@ -165,8 +200,9 @@ int semget(int semKey, int semNum, int flags) void* Ad; long i; - /* Limit to 500 semaphore in a pool */ - if (semNum>500) + /* Limit to 250 (8 byte per sem : 4 for the semid and 4 for the last pid + which acceced the semaphore in a pool */ + if (semNum>250) { errno=ENOSPC; return -1; @@ -183,12 +219,12 @@ int semget(int semKey, int semNum, int flags) /* fill up informations (sem number and sem ids) */ Address=(int32*)Ad; Address[0]=semNum; - for (i=1;i<=Address[0];i++) + for (i=0;i 0) { - release_sem_etc(Address[sops[i].sem_num+1],sops[i].sem_op,0); + release_sem_etc(Address[2*(sops[i].sem_num)+1],sops[i].sem_op,0); } } + return 0; } diff --git a/src/backend/port/dynloader/beos.c b/src/backend/port/dynloader/beos.c index ea97057e62..2a516e66c6 100644 --- a/src/backend/port/dynloader/beos.c +++ b/src/backend/port/dynloader/beos.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/port/dynloader/Attic/beos.c,v 1.3 2000/10/07 14:39:11 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/port/dynloader/Attic/beos.c,v 1.4 2000/12/18 18:45:04 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -51,6 +51,11 @@ pg_dlsym(void *handle, char *funcname) /* Loading symbol */ if(get_image_symbol(*((int*)(handle)),funcname,B_SYMBOL_TYPE_TEXT,(void**)&fpt)==B_OK); { + /* Sometime the loader return B_OK for an inexistant function with an invalid address !!! + Check that the return address is in the image range */ + image_info info; + get_image_info(*((int*)(handle)),&info); + if ((fpt=(info.text+info.text_size))) return NULL; return fpt; } elog(NOTICE, "loading symbol '%s' failed ",funcname); diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index c119f1301f..e1c8021ff0 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.199 2000/12/18 17:33:40 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.200 2000/12/18 18:45:04 momjian Exp $ * * NOTES * @@ -2181,6 +2181,11 @@ SSDataBase(int xlop) fflush(stdout); fflush(stderr); +#ifdef __BEOS__ + /* Specific beos actions before backend startup */ + beos_before_backend_startup(); +#endif + if ((pid = fork()) == 0) /* child */ { char *av[ARGV_SIZE * 2]; @@ -2189,6 +2194,11 @@ SSDataBase(int xlop) char dbbuf[ARGV_SIZE]; char xlbuf[ARGV_SIZE]; +#ifdef __BEOS__ + /* Specific beos actions after backend startup */ + beos_backend_startup(); +#endif + /* Lose the postmaster's on-exit routines and port connections */ on_exit_reset(); @@ -2234,6 +2244,11 @@ SSDataBase(int xlop) /* in parent */ if (pid < 0) { +#ifdef __BEOS__ + /* Specific beos actions before backend startup */ + beos_backend_startup_failed(); +#endif + fprintf(stderr, "%s Data Base: fork failed: %s\n", ((xlop == BS_XLOG_STARTUP) ? "Startup" : ((xlop == BS_XLOG_CHECKPOINT) ? "CheckPoint" : diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 02c1459052..2946c9a5ef 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.196 2000/12/18 17:33:41 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.197 2000/12/18 18:45:05 momjian Exp $ * * NOTES * this is the "main" module of the postgres backend and @@ -1649,7 +1649,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha if (!IsUnderPostmaster) { puts("\nPOSTGRES backend interactive interface "); - puts("$Revision: 1.196 $ $Date: 2000/12/18 17:33:41 $\n"); + puts("$Revision: 1.197 $ $Date: 2000/12/18 18:45:05 $\n"); } /* @@ -1950,7 +1950,7 @@ ShowUsage(void) (long int) sys.tv_sec, (long int) sys.tv_usec); /* BeOS has rusage but only has some fields, and not these... */ -#if defined(HAVE_GETRUSAGE) && !defined(__BEOS__) +#if defined(HAVE_GETRUSAGE) fprintf(StatFp, "!\t%ld/%ld [%ld/%ld] filesystem blocks in/out\n", r.ru_inblock - Save_r.ru_inblock, diff --git a/src/include/port/beos.h b/src/include/port/beos.h index 0618dc3ffd..38a8eaa79e 100644 --- a/src/include/port/beos.h +++ b/src/include/port/beos.h @@ -5,7 +5,13 @@ typedef unsigned char slock_t; -#define AF_UNIX 1 /* no domain sockets on BeOS */ +#define AF_UNIX 10 /* no domain sockets on BeOS */ + +/* Beos doesn't have sysnerr but strerror should works on every error */ +extern int sys_nerr; + +/* Beos doesn't have all the required getrusage fields */ +#undef HAVE_GETRUSAGE /* SYS V emulation */ @@ -16,6 +22,7 @@ typedef unsigned char slock_t; #define IPC_CREAT 512 #define IPC_EXCL 1024 #define IPC_PRIVATE 234564 +#define IPC_NOWAIT 2048 #define EACCESS 2048 #define EIDRM 4096 @@ -24,6 +31,7 @@ typedef unsigned char slock_t; #define GETNCNT 16384 #define GETVAL 65536 #define SETVAL 131072 +#define GETPID 262144 union semun { -- 2.40.0