mirror of
https://github.com/postgres/postgres.git
synced 2025-11-13 16:22:44 +03:00
pgindent run. Make it all clean.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* BeOS System V Semaphores Emulation
|
||||
*
|
||||
* Copyright (c) 1999-2000, Cyril VELTER
|
||||
*
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
@@ -29,204 +29,227 @@
|
||||
|
||||
/* 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
|
||||
in the pool followed by SemIds */
|
||||
in the pool followed by SemIds */
|
||||
|
||||
int semctl(int semId,int semNum,int flag,union semun semun)
|
||||
int
|
||||
semctl(int semId, int semNum, int flag, union semun semun)
|
||||
{
|
||||
int32* Address;
|
||||
area_info info;
|
||||
int32 *Address;
|
||||
area_info info;
|
||||
|
||||
TRACEDBG("->semctl");
|
||||
/* Try to find the pool */
|
||||
if (get_area_info(semId,&info)!=B_OK)
|
||||
if (get_area_info(semId, &info) != B_OK)
|
||||
{
|
||||
/* pool is invalid (BeOS area id is invalid) */
|
||||
errno=EINVAL;
|
||||
errno = EINVAL;
|
||||
TRACEDBG("<-semctl invalid pool");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Get the pool address */
|
||||
Address=(int32*)info.address;
|
||||
TRACEDBGP("--semctl address %d",Address);
|
||||
|
||||
|
||||
Address = (int32 *) info.address;
|
||||
TRACEDBGP("--semctl address %d", Address);
|
||||
|
||||
|
||||
/* semNum might be 0 */
|
||||
/* semun.array contain the sem initial values */
|
||||
|
||||
|
||||
/* Fix the count of all sem of the pool to semun.array */
|
||||
if (flag==SETALL)
|
||||
if (flag == SETALL)
|
||||
{
|
||||
long i;
|
||||
long i;
|
||||
|
||||
TRACEDBG("--semctl setall");
|
||||
for (i=0;i<Address[0];i++)
|
||||
for (i = 0; i < Address[0]; i++)
|
||||
{
|
||||
int32 cnt;
|
||||
int32 cnt;
|
||||
|
||||
/* Get the current count */
|
||||
get_sem_count(Address[2*i+1],&cnt);
|
||||
|
||||
TRACEDBGP("--semctl setall %d",semun.array[i]);
|
||||
get_sem_count(Address[2 * i + 1], &cnt);
|
||||
|
||||
TRACEDBGP("--semctl setall %d", semun.array[i]);
|
||||
|
||||
/* Compute and set the new count (relative to the old one) */
|
||||
cnt-=semun.array[i];
|
||||
TRACEDBGPP("--semctl acquire id : %d cnt : %d",Address[2*i+1],cnt);
|
||||
cnt -= semun.array[i];
|
||||
TRACEDBGPP("--semctl acquire id : %d cnt : %d", Address[2 * i + 1], cnt);
|
||||
if (cnt > 0)
|
||||
while(acquire_sem_etc(Address[2*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[2*i+1],-cnt,0);
|
||||
release_sem_etc(Address[2 * i + 1], -cnt, 0);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Fix the count of one semaphore to semun.val */
|
||||
if (flag==SETVAL)
|
||||
if (flag == SETVAL)
|
||||
{
|
||||
int32 cnt;
|
||||
TRACEDBGP("--semctl setval %d",semun.val);
|
||||
int32 cnt;
|
||||
|
||||
TRACEDBGP("--semctl setval %d", semun.val);
|
||||
/* Get the current count */
|
||||
get_sem_count(Address[2*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);
|
||||
cnt -= semun.val;
|
||||
TRACEDBGPP("--semctl acquire id : %d cnt : %d", Address[2 * semNum + 1], cnt);
|
||||
if (cnt > 0)
|
||||
while(acquire_sem_etc(Address[2*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[2*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)
|
||||
if (flag == GETPID)
|
||||
{
|
||||
TRACEDBG("->semctl getpid");
|
||||
return Address[2*semNum+2];
|
||||
return Address[2 * semNum + 2];
|
||||
}
|
||||
|
||||
|
||||
/* Delete the pool */
|
||||
if (flag==IPC_RMID)
|
||||
if (flag == IPC_RMID)
|
||||
{
|
||||
long i;
|
||||
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;i<Address[0];i++)
|
||||
{
|
||||
/* Make sure to have ownership of the semaphore (if created by another team) */
|
||||
TRACEDBGP("->semctl id %d",Address[2*i+1]);
|
||||
set_sem_owner(Address[2*i+1],ti.team);
|
||||
|
||||
/* Delete the semaphore */
|
||||
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[2*i+1]=0;
|
||||
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; i < Address[0]; i++)
|
||||
{
|
||||
|
||||
/*
|
||||
* Make sure to have ownership of the semaphore (if created by
|
||||
* another team)
|
||||
*/
|
||||
TRACEDBGP("->semctl id %d", Address[2 * i + 1]);
|
||||
set_sem_owner(Address[2 * i + 1], ti.team);
|
||||
|
||||
/* Delete the semaphore */
|
||||
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[2 * i + 1] = 0;
|
||||
}
|
||||
|
||||
|
||||
/* Set the semaphore count to 0 */
|
||||
Address[0]=0;
|
||||
|
||||
/* Delete the area (it might be cloned by other process. Let them live with it,
|
||||
in all cases semIds are 0 so if another process try to use it, it will fail */
|
||||
Address[0] = 0;
|
||||
|
||||
/*
|
||||
* Delete the area (it might be cloned by other process. Let them
|
||||
* live with it, in all cases semIds are 0 so if another process
|
||||
* try to use it, it will fail
|
||||
*/
|
||||
delete_area(semId);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Get the current semaphore count */
|
||||
if (flag==GETNCNT)
|
||||
if (flag == GETNCNT)
|
||||
{
|
||||
/* TO BE IMPLEMENTED */
|
||||
TRACEDBG("--semctl getncnt");
|
||||
elog(ERROR,"beos : semctl error : GETNCNT not implemented");
|
||||
elog(ERROR, "beos : semctl error : GETNCNT not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Get the current semaphore count of the first semaphore in the pool */
|
||||
if (flag==GETVAL)
|
||||
if (flag == GETVAL)
|
||||
{
|
||||
int32 cnt;
|
||||
int32 cnt;
|
||||
|
||||
TRACEDBG("--semctl getval");
|
||||
get_sem_count(Address[2*semNum+1],&cnt);
|
||||
TRACEDBGP("--semctl val %d",cnt);
|
||||
get_sem_count(Address[2 * semNum + 1], &cnt);
|
||||
TRACEDBGP("--semctl val %d", cnt);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
elog(ERROR,"beos : semctl error : unknown flag");
|
||||
elog(ERROR, "beos : semctl error : unknown flag");
|
||||
|
||||
TRACEDBG("<-semctl unknown flag");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Find a pool id based on IPC key */
|
||||
int semget(int semKey, int semNum, int flags)
|
||||
int
|
||||
semget(int semKey, int semNum, int flags)
|
||||
{
|
||||
char Nom[50];
|
||||
area_id parea;
|
||||
void* Address;
|
||||
char Nom[50];
|
||||
area_id parea;
|
||||
void *Address;
|
||||
|
||||
TRACEDBGPP("->semget key : %d num : %d",semKey,semNum);
|
||||
TRACEDBGPP("->semget key : %d num : %d", semKey, semNum);
|
||||
/* Name of the area to find */
|
||||
sprintf(Nom,"SYSV_IPC_SEM : %d",semKey);
|
||||
sprintf(Nom, "SYSV_IPC_SEM : %d", semKey);
|
||||
|
||||
/* find area */
|
||||
parea=find_area(Nom);
|
||||
parea = find_area(Nom);
|
||||
|
||||
/* Test of area existance */
|
||||
if (parea!=B_NAME_NOT_FOUND)
|
||||
if (parea != B_NAME_NOT_FOUND)
|
||||
{
|
||||
/* Area exist and creation is requested, error */
|
||||
if ((flags&IPC_CREAT)&&(flags&IPC_EXCL))
|
||||
if ((flags & IPC_CREAT) && (flags & IPC_EXCL))
|
||||
{
|
||||
errno=EEXIST;
|
||||
errno = EEXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Get an area clone (in case it's not in our address space) */
|
||||
/* TODO : a check of address space might be done to avoid duplicate areas in the same address space*/
|
||||
parea=clone_area(Nom,&Address,B_ANY_ADDRESS,B_READ_AREA | B_WRITE_AREA,parea);
|
||||
|
||||
/*
|
||||
* TODO : a check of address space might be done to avoid
|
||||
* duplicate areas in the same address space
|
||||
*/
|
||||
parea = clone_area(Nom, &Address, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA, parea);
|
||||
return parea;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Area does not exist, but creation is requested, so create it */
|
||||
if (flags&IPC_CREAT)
|
||||
if (flags & IPC_CREAT)
|
||||
{
|
||||
int32* Address;
|
||||
void* Ad;
|
||||
long i;
|
||||
int32 *Address;
|
||||
void *Ad;
|
||||
long i;
|
||||
|
||||
/* 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)
|
||||
/*
|
||||
* 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;
|
||||
errno = ENOSPC;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Create the shared memory area which will hold the pool */
|
||||
parea=create_area(Nom,&Ad,B_ANY_ADDRESS,4096,B_NO_LOCK,B_READ_AREA | B_WRITE_AREA);
|
||||
if ((parea==B_BAD_VALUE)|| (parea==B_NO_MEMORY)||(parea==B_ERROR))
|
||||
parea = create_area(Nom, &Ad, B_ANY_ADDRESS, 4096, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
|
||||
if ((parea == B_BAD_VALUE) || (parea == B_NO_MEMORY) || (parea == B_ERROR))
|
||||
{
|
||||
errno=ENOMEM;
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* fill up informations (sem number and sem ids) */
|
||||
Address=(int32*)Ad;
|
||||
Address[0]=semNum;
|
||||
for (i=0;i<Address[0];i++)
|
||||
Address = (int32 *) Ad;
|
||||
Address[0] = semNum;
|
||||
for (i = 0; i < Address[0]; i++)
|
||||
{
|
||||
/* Create the semaphores */
|
||||
Address[2*i+1]=create_sem(0,Nom);
|
||||
|
||||
if ((Address[2*i+1]==B_BAD_VALUE)|| (Address[2*i+1]==B_NO_MEMORY)||(Address[2*i+1]==B_NO_MORE_SEMS))
|
||||
Address[2 * i + 1] = create_sem(0, Nom);
|
||||
|
||||
if ((Address[2 * i + 1] == B_BAD_VALUE) || (Address[2 * i + 1] == B_NO_MEMORY) || (Address[2 * i + 1] == B_NO_MORE_SEMS))
|
||||
{
|
||||
errno=ENOMEM;
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -236,59 +259,58 @@ int semget(int semKey, int semNum, int flags)
|
||||
else
|
||||
{
|
||||
/* Area does not exist and no creation is requested */
|
||||
errno=ENOENT;
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Acquire or release in the semaphore pool */
|
||||
int semop(int semId, struct sembuf *sops, int nsops)
|
||||
int
|
||||
semop(int semId, struct sembuf * sops, int nsops)
|
||||
{
|
||||
int32* Address; /*Pool address*/
|
||||
area_info info;
|
||||
long i;
|
||||
long ret;
|
||||
int32 *Address; /* Pool address */
|
||||
area_info info;
|
||||
long i;
|
||||
long ret;
|
||||
|
||||
/* Get the pool address (semId IS an area id) */
|
||||
get_area_info(semId,&info);
|
||||
Address=(int32*)info.address;
|
||||
|
||||
get_area_info(semId, &info);
|
||||
Address = (int32 *) info.address;
|
||||
|
||||
/* Check the validity of semId (it should be an area id) */
|
||||
if ((semId==B_BAD_VALUE)||(semId==B_NO_MEMORY)||(semId==B_ERROR))
|
||||
if ((semId == B_BAD_VALUE) || (semId == B_NO_MEMORY) || (semId == B_ERROR))
|
||||
{
|
||||
errno=EINVAL;
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Perform acquire or release */
|
||||
for(i=0;i<nsops;i++)
|
||||
for (i = 0; i < nsops; i++)
|
||||
{
|
||||
/* remember the PID */
|
||||
Address[2*(sops[i].sem_num)+2]=getpid();
|
||||
|
||||
Address[2 * (sops[i].sem_num) + 2] = getpid();
|
||||
|
||||
/* For each sem in the pool, check the operation to perform */
|
||||
if (sops[i].sem_op < 0)
|
||||
{
|
||||
/* Try acuiring the semaphore till we are not inteerupted by a signal */
|
||||
if (sops[i].sem_flg==IPC_NOWAIT)
|
||||
|
||||
/*
|
||||
* Try acuiring the semaphore till we are not inteerupted by a
|
||||
* signal
|
||||
*/
|
||||
if (sops[i].sem_flg == IPC_NOWAIT)
|
||||
{
|
||||
/* Try to lock ... */
|
||||
while ((ret=acquire_sem_etc(Address[2*(sops[i].sem_num)+1],-sops[i].sem_op,B_RELATIVE_TIMEOUT,0))==B_INTERRUPTED);
|
||||
if (ret!=B_OK)
|
||||
{
|
||||
while ((ret = acquire_sem_etc(Address[2 * (sops[i].sem_num) + 1], -sops[i].sem_op, B_RELATIVE_TIMEOUT, 0)) == B_INTERRUPTED);
|
||||
if (ret != B_OK)
|
||||
return EWOULDBLOCK;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (acquire_sem_etc(Address[2*(sops[i].sem_num)+1],-sops[i].sem_op,0,0)==B_INTERRUPTED);
|
||||
}
|
||||
while (acquire_sem_etc(Address[2 * (sops[i].sem_num) + 1], -sops[i].sem_op, 0, 0) == B_INTERRUPTED);
|
||||
}
|
||||
if (sops[i].sem_op > 0)
|
||||
{
|
||||
release_sem_etc(Address[2*(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;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* BeOS System V Shared Memory Emulation
|
||||
*
|
||||
* Copyright (c) 1999-2001, Cyril VELTER
|
||||
*
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
@@ -18,48 +18,61 @@ areas in copy on write mode */
|
||||
|
||||
|
||||
/* Detach from a shared mem area based on its address */
|
||||
int shmdt(char* shmaddr)
|
||||
int
|
||||
shmdt(char *shmaddr)
|
||||
{
|
||||
/* Find area id for this address */
|
||||
area_id s;
|
||||
s=area_for(shmaddr);
|
||||
area_id s;
|
||||
|
||||
s = area_for(shmaddr);
|
||||
|
||||
/* Delete area */
|
||||
return delete_area(s);
|
||||
}
|
||||
|
||||
/* Attach to an existing area */
|
||||
int* shmat(int memId,int m1,int m2)
|
||||
int *
|
||||
shmat(int memId, int m1, int m2)
|
||||
{
|
||||
/* Get our team id */
|
||||
thread_info thinfo;
|
||||
team_info teinfo;
|
||||
area_info ainfo;
|
||||
|
||||
get_thread_info(find_thread(NULL),&thinfo);
|
||||
get_team_info(thinfo.team,&teinfo);
|
||||
|
||||
team_info teinfo;
|
||||
area_info ainfo;
|
||||
|
||||
get_thread_info(find_thread(NULL), &thinfo);
|
||||
get_team_info(thinfo.team, &teinfo);
|
||||
|
||||
/* Get area teamid */
|
||||
if (get_area_info(memId,&ainfo)!=B_OK)
|
||||
printf("AREA %d Invalide\n",memId);
|
||||
|
||||
if (ainfo.team==teinfo.team)
|
||||
if (get_area_info(memId, &ainfo) != B_OK)
|
||||
printf("AREA %d Invalide\n", memId);
|
||||
|
||||
if (ainfo.team == teinfo.team)
|
||||
{
|
||||
/* the area is already in our address space, just return the address */
|
||||
return (int*)ainfo.address;
|
||||
}
|
||||
|
||||
/*
|
||||
* the area is already in our address space, just return the
|
||||
* address
|
||||
*/
|
||||
return (int *) ainfo.address;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* the area is not in our address space, clone it before and return the address */
|
||||
area_id narea;
|
||||
narea = clone_area(ainfo.name,&(ainfo.address),B_CLONE_ADDRESS,B_READ_AREA | B_WRITE_AREA,memId);
|
||||
get_area_info(narea,&ainfo);
|
||||
return (int*)ainfo.address;
|
||||
|
||||
/*
|
||||
* the area is not in our address space, clone it before and
|
||||
* return the address
|
||||
*/
|
||||
area_id narea;
|
||||
|
||||
narea = clone_area(ainfo.name, &(ainfo.address), B_CLONE_ADDRESS, B_READ_AREA | B_WRITE_AREA, memId);
|
||||
get_area_info(narea, &ainfo);
|
||||
return (int *) ainfo.address;
|
||||
}
|
||||
}
|
||||
|
||||
/* Control a shared mem area */
|
||||
int shmctl(int shmid, int flag, struct shmid_ds* dummy)
|
||||
int
|
||||
shmctl(int shmid, int flag, struct shmid_ds * dummy)
|
||||
{
|
||||
if (flag == IPC_RMID)
|
||||
{
|
||||
@@ -71,26 +84,26 @@ int shmctl(int shmid, int flag, struct shmid_ds* dummy)
|
||||
{
|
||||
/* Find any SYSV area with the shmid in its name */
|
||||
|
||||
area_info inf;
|
||||
team_info infteam;
|
||||
int32 cookteam=0;
|
||||
char name[50];
|
||||
sprintf(name,"SYSV_IPC %d",shmid);
|
||||
|
||||
dummy->shm_nattch=0;
|
||||
|
||||
area_info inf;
|
||||
team_info infteam;
|
||||
int32 cookteam = 0;
|
||||
char name[50];
|
||||
|
||||
sprintf(name, "SYSV_IPC %d", shmid);
|
||||
|
||||
dummy->shm_nattch = 0;
|
||||
|
||||
while (get_next_team_info(&cookteam, &infteam) == B_OK)
|
||||
{
|
||||
int32 cook=0;
|
||||
{
|
||||
int32 cook = 0;
|
||||
|
||||
while (get_next_area_info(infteam.team, &cook, &inf) == B_OK)
|
||||
{
|
||||
if (strcmp(name,inf.name) == 0)
|
||||
{
|
||||
dummy->shm_nattch++;
|
||||
}
|
||||
if (strcmp(name, inf.name) == 0)
|
||||
dummy->shm_nattch++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
errno = 0;
|
||||
return 0;
|
||||
}
|
||||
@@ -99,31 +112,30 @@ int shmctl(int shmid, int flag, struct shmid_ds* dummy)
|
||||
}
|
||||
|
||||
/* Get an area based on the IPC key */
|
||||
int shmget(int memKey,int size,int flag)
|
||||
int
|
||||
shmget(int memKey, int size, int flag)
|
||||
{
|
||||
char nom[50];
|
||||
void* Address;
|
||||
area_id parea;
|
||||
char nom[50];
|
||||
void *Address;
|
||||
area_id parea;
|
||||
|
||||
/* Area name */
|
||||
sprintf(nom,"SYSV_IPC_SHM : %d",memKey);
|
||||
sprintf(nom, "SYSV_IPC_SHM : %d", memKey);
|
||||
|
||||
/* Find area */
|
||||
parea=find_area(nom);
|
||||
|
||||
parea = find_area(nom);
|
||||
|
||||
/* area exist, just return its id */
|
||||
if (parea!=B_NAME_NOT_FOUND)
|
||||
{
|
||||
if (parea != B_NAME_NOT_FOUND)
|
||||
return parea;
|
||||
}
|
||||
|
||||
/* area does not exist and no creation is requested : error */
|
||||
if (flag==0)
|
||||
{
|
||||
if (flag == 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* area does not exist and its creation is requested, create it (be sure to have a 4ko multiple size */
|
||||
return create_area(nom,&Address,B_ANY_ADDRESS,((size/4096)+1)*4096,B_NO_LOCK,B_READ_AREA | B_WRITE_AREA);
|
||||
}
|
||||
|
||||
/*
|
||||
* area does not exist and its creation is requested, create it (be
|
||||
* sure to have a 4ko multiple size
|
||||
*/
|
||||
return create_area(nom, &Address, B_ANY_ADDRESS, ((size / 4096) + 1) * 4096, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA);
|
||||
}
|
||||
|
||||
@@ -4,19 +4,19 @@
|
||||
* BeOS Support functions
|
||||
*
|
||||
* Copyright (c) 1999-2001, Cyril VELTER
|
||||
*
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
/* Support Globals */
|
||||
port_id beos_dl_port_in=0;
|
||||
port_id beos_dl_port_out=0;
|
||||
sem_id beos_shm_sem;
|
||||
port_id beos_dl_port_in = 0;
|
||||
port_id beos_dl_port_out = 0;
|
||||
sem_id beos_shm_sem;
|
||||
|
||||
/* Global var containing the postgres path */
|
||||
extern char pg_pathname[];
|
||||
extern char pg_pathname[];
|
||||
|
||||
|
||||
/* Shared library loading doesn't work after fork in beos. The solution is to use an exact
|
||||
@@ -27,185 +27,194 @@ postgres executable just run a loop to wait command on a port. Its only action i
|
||||
the beos_dl_open will then remap the good areas in the backend address space. */
|
||||
|
||||
|
||||
image_id beos_dl_open(char * filename)
|
||||
image_id
|
||||
beos_dl_open(char *filename)
|
||||
{
|
||||
image_id im;
|
||||
image_id im;
|
||||
|
||||
/* If a port doesn't exist, lauch support server */
|
||||
if ((beos_dl_port_in<=0)||(beos_dl_port_out<=0))
|
||||
/* If a port doesn't exist, lauch support server */
|
||||
if ((beos_dl_port_in <= 0) || (beos_dl_port_out <= 0))
|
||||
{
|
||||
/* Create communication port */
|
||||
beos_dl_port_in=create_port(50,"beos_support_in");
|
||||
beos_dl_port_out=create_port(50,"beos_support_in");
|
||||
beos_dl_port_in = create_port(50, "beos_support_in");
|
||||
beos_dl_port_out = create_port(50, "beos_support_in");
|
||||
|
||||
|
||||
if ((beos_dl_port_in<=0)||(beos_dl_port_out<=0))
|
||||
if ((beos_dl_port_in <= 0) || (beos_dl_port_out <= 0))
|
||||
{
|
||||
elog(NOTICE, "Error loading BeOS support server : can't create communication ports");
|
||||
elog(NOTICE, "Error loading BeOS support server : can't create communication ports");
|
||||
return B_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
char Cmd[4000];
|
||||
|
||||
char Cmd[4000];
|
||||
|
||||
/* Build arg list */
|
||||
sprintf(Cmd,"%s -beossupportserver %d %d &",pg_pathname,(int)beos_dl_port_in,(int)beos_dl_port_out);
|
||||
sprintf(Cmd, "%s -beossupportserver %d %d &", pg_pathname, (int) beos_dl_port_in, (int) beos_dl_port_out);
|
||||
|
||||
/* Lauch process */
|
||||
system(Cmd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Add-on loading */
|
||||
|
||||
|
||||
/* Send command '1' (load) to the support server */
|
||||
write_port(beos_dl_port_in,1,filename,strlen(filename)+1);
|
||||
|
||||
write_port(beos_dl_port_in, 1, filename, strlen(filename) + 1);
|
||||
|
||||
/* Read Object Id */
|
||||
read_port(beos_dl_port_out,&im,NULL,0);
|
||||
read_port(beos_dl_port_out, &im, NULL, 0);
|
||||
|
||||
/* Checking integrity */
|
||||
if (im<0)
|
||||
{
|
||||
if (im < 0)
|
||||
{
|
||||
elog(NOTICE, "Can't load this add-on ");
|
||||
return B_ERROR;
|
||||
return B_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Map text and data segment in our address space */
|
||||
char datas[4000];
|
||||
int32 area;
|
||||
int32 resu;
|
||||
void* add;
|
||||
|
||||
char datas[4000];
|
||||
int32 area;
|
||||
int32 resu;
|
||||
void *add;
|
||||
|
||||
/* read text segment id and address */
|
||||
read_port(beos_dl_port_out,&area,datas,4000);
|
||||
read_port(beos_dl_port_out,(void*)&add,datas,4000);
|
||||
read_port(beos_dl_port_out, &area, datas, 4000);
|
||||
read_port(beos_dl_port_out, (void *) &add, datas, 4000);
|
||||
/* map text segment in our address space */
|
||||
resu=clone_area(datas,&add,B_EXACT_ADDRESS,B_READ_AREA|B_WRITE_AREA,area);
|
||||
if (resu<0)
|
||||
resu = clone_area(datas, &add, B_EXACT_ADDRESS, B_READ_AREA | B_WRITE_AREA, area);
|
||||
if (resu < 0)
|
||||
{
|
||||
/* If we can't map, we are in reload case */
|
||||
/* delete the mapping */
|
||||
resu=delete_area(area_for(add));
|
||||
resu = delete_area(area_for(add));
|
||||
/* Remap */
|
||||
resu=clone_area(datas,&add,B_EXACT_ADDRESS,B_READ_AREA|B_WRITE_AREA,area);
|
||||
if (resu<0)
|
||||
{
|
||||
resu = clone_area(datas, &add, B_EXACT_ADDRESS, B_READ_AREA | B_WRITE_AREA, area);
|
||||
if (resu < 0)
|
||||
elog(NOTICE, "Can't load this add-on : map text error");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* read text segment id and address */
|
||||
read_port(beos_dl_port_out,&area,datas,4000);
|
||||
read_port(beos_dl_port_out,(void*)&add,datas,4000);
|
||||
read_port(beos_dl_port_out, &area, datas, 4000);
|
||||
read_port(beos_dl_port_out, (void *) &add, datas, 4000);
|
||||
/* map text segment in our address space */
|
||||
resu=clone_area(datas,&add,B_EXACT_ADDRESS,B_READ_AREA|B_WRITE_AREA,area);
|
||||
if (resu<0)
|
||||
resu = clone_area(datas, &add, B_EXACT_ADDRESS, B_READ_AREA | B_WRITE_AREA, area);
|
||||
if (resu < 0)
|
||||
{
|
||||
/* If we can't map, we are in reload case */
|
||||
/* delete the mapping */
|
||||
resu=delete_area(area_for(add));
|
||||
resu = delete_area(area_for(add));
|
||||
/* Remap */
|
||||
resu=clone_area(datas,&add,B_EXACT_ADDRESS,B_READ_AREA|B_WRITE_AREA,area);
|
||||
if (resu<0)
|
||||
{
|
||||
resu = clone_area(datas, &add, B_EXACT_ADDRESS, B_READ_AREA | B_WRITE_AREA, area);
|
||||
if (resu < 0)
|
||||
elog(NOTICE, "Can't load this add-on : map data error");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return im;
|
||||
}
|
||||
}
|
||||
|
||||
status_t beos_dl_close(image_id im)
|
||||
status_t
|
||||
beos_dl_close(image_id im)
|
||||
{
|
||||
/* unload add-on */
|
||||
int32 resu;
|
||||
write_port(beos_dl_port_in,2,&im,4);
|
||||
read_port(beos_dl_port_out,&resu,NULL,0);
|
||||
int32 resu;
|
||||
|
||||
write_port(beos_dl_port_in, 2, &im, 4);
|
||||
read_port(beos_dl_port_out, &resu, NULL, 0);
|
||||
return resu;
|
||||
}
|
||||
|
||||
/* Main support server loop */
|
||||
|
||||
void beos_startup(int argc,char** argv)
|
||||
void
|
||||
beos_startup(int argc, char **argv)
|
||||
{
|
||||
if (strlen(argv[0]) >= 10 && !strcmp(argv[0] + strlen(argv[0]) - 10, "postmaster"))
|
||||
{
|
||||
/* We are in the postmaster, create the protection semaphore for shared mem remapping */
|
||||
beos_shm_sem=create_sem(1,"beos_shm_sem");
|
||||
|
||||
/*
|
||||
* We are in the postmaster, create the protection semaphore for
|
||||
* shared mem remapping
|
||||
*/
|
||||
beos_shm_sem = create_sem(1, "beos_shm_sem");
|
||||
}
|
||||
|
||||
if (argc > 1 && strcmp(argv[1], "-beossupportserver") == 0)
|
||||
{
|
||||
/* We are in the support server, run it ... */
|
||||
|
||||
port_id port_in;
|
||||
port_id port_out;
|
||||
|
||||
port_id port_in;
|
||||
port_id port_out;
|
||||
|
||||
/* Get back port ids from arglist */
|
||||
sscanf(argv[2],"%d",(int*)(&port_in));
|
||||
sscanf(argv[3],"%d",(int*)(&port_out));
|
||||
|
||||
sscanf(argv[2], "%d", (int *) (&port_in));
|
||||
sscanf(argv[3], "%d", (int *) (&port_out));
|
||||
|
||||
/* Main server loop */
|
||||
for (;;)
|
||||
{
|
||||
int32 opcode=0;
|
||||
char datas[4000];
|
||||
|
||||
/* Wait for a message from the backend :
|
||||
1 : load a shared object
|
||||
2 : unload a shared object
|
||||
any other : exit support server */
|
||||
read_port(port_in,&opcode,datas,4000);
|
||||
|
||||
switch(opcode)
|
||||
{
|
||||
int32 opcode = 0;
|
||||
char datas[4000];
|
||||
|
||||
/*
|
||||
* Wait for a message from the backend : 1 : load a shared
|
||||
* object 2 : unload a shared object any other : exit support
|
||||
* server
|
||||
*/
|
||||
read_port(port_in, &opcode, datas, 4000);
|
||||
|
||||
switch (opcode)
|
||||
{
|
||||
image_id addon;
|
||||
image_info info_im;
|
||||
area_info info_ar;
|
||||
|
||||
/* Load Add-On */
|
||||
case 1 :
|
||||
|
||||
image_id addon;
|
||||
image_info info_im;
|
||||
area_info info_ar;
|
||||
|
||||
/* Load Add-On */
|
||||
case 1:
|
||||
|
||||
/* Load shared object */
|
||||
addon=load_add_on(datas);
|
||||
|
||||
addon = load_add_on(datas);
|
||||
|
||||
/* send back the shared object Id */
|
||||
write_port(port_out,addon,NULL,0);
|
||||
|
||||
write_port(port_out, addon, NULL, 0);
|
||||
|
||||
/* Get Shared Object infos */
|
||||
get_image_info(addon,&info_im);
|
||||
|
||||
get_image_info(addon, &info_im);
|
||||
|
||||
/* get text segment info */
|
||||
get_area_info(area_for(info_im.text),&info_ar);
|
||||
get_area_info(area_for(info_im.text), &info_ar);
|
||||
/* Send back area_id of text segment */
|
||||
write_port(port_out,info_ar.area,info_ar.name,strlen(info_ar.name)+1);
|
||||
write_port(port_out, info_ar.area, info_ar.name, strlen(info_ar.name) + 1);
|
||||
/* Send back real address of text segment */
|
||||
write_port(port_out,(int)info_ar.address,info_ar.name,strlen(info_ar.name)+1);
|
||||
|
||||
|
||||
write_port(port_out, (int) info_ar.address, info_ar.name, strlen(info_ar.name) + 1);
|
||||
|
||||
|
||||
/* get data segment info */
|
||||
get_area_info(area_for(info_im.data),&info_ar);
|
||||
get_area_info(area_for(info_im.data), &info_ar);
|
||||
/* Send back area_id of data segment */
|
||||
write_port(port_out,info_ar.area,info_ar.name,strlen(info_ar.name)+1);
|
||||
write_port(port_out, info_ar.area, info_ar.name, strlen(info_ar.name) + 1);
|
||||
/* Send back real address of data segment */
|
||||
write_port(port_out,(int)info_ar.address,info_ar.name,strlen(info_ar.name)+1);
|
||||
break;
|
||||
/* UnLoad Add-On */
|
||||
case 2 :
|
||||
/* Unload shared object and send back the result of the operation */
|
||||
write_port(port_out,unload_add_on(*((int*)(datas))),NULL,0);
|
||||
break;
|
||||
/* Cleanup and exit */
|
||||
write_port(port_out, (int) info_ar.address, info_ar.name, strlen(info_ar.name) + 1);
|
||||
break;
|
||||
/* UnLoad Add-On */
|
||||
case 2:
|
||||
|
||||
/*
|
||||
* Unload shared object and send back the result of
|
||||
* the operation
|
||||
*/
|
||||
write_port(port_out, unload_add_on(*((int *) (datas))), NULL, 0);
|
||||
break;
|
||||
/* Cleanup and exit */
|
||||
default:
|
||||
/* Free system resources */
|
||||
delete_port(port_in);
|
||||
delete_port(port_out);
|
||||
/* Exit */
|
||||
exit(0);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Never be there */
|
||||
@@ -215,76 +224,80 @@ void beos_startup(int argc,char** argv)
|
||||
|
||||
|
||||
|
||||
/* The behavior of fork is borken on beos regarding shared memory. In fact
|
||||
/* The behavior of fork is borken on beos regarding shared memory. In fact
|
||||
all shared memory areas are clones in copy on write mode in the new process.
|
||||
|
||||
We need to do a remapping of these areas. Just afer the fork we performe the
|
||||
following actions :
|
||||
|
||||
* Find all areas with a name begining by SYS_V_IPC_ in our process
|
||||
(areas created by the SYSV IPC emulation functions). The name is
|
||||
followed by the IPC KEY in decimal format
|
||||
|
||||
(areas created by the SYSV IPC emulation functions). The name is
|
||||
followed by the IPC KEY in decimal format
|
||||
|
||||
* For each area we do :
|
||||
|
||||
|
||||
* 1 : Get its name
|
||||
* 2 : destroy it
|
||||
* 3 : find another area with the exact same name
|
||||
* 3 : find another area with the exact same name
|
||||
* 4 : clone it in our address space with a different name
|
||||
|
||||
|
||||
There is a race condition in 3-4 : if there two fork in a very short
|
||||
time, in step 3 we might end up with two areas with the same name, and no
|
||||
possibility to find the postmaster one. So the whole process is protected
|
||||
by a semaphore which is acquires just before the fork and released in case
|
||||
of fork failure or just after the end of the remapping.*/
|
||||
|
||||
void beos_before_backend_startup(void)
|
||||
|
||||
void
|
||||
beos_before_backend_startup(void)
|
||||
{
|
||||
/* Just before forking, acquire the semaphore */
|
||||
if(acquire_sem(beos_shm_sem)!=B_OK)
|
||||
exit(1); /* Fatal error, exiting with error */
|
||||
/* Just before forking, acquire the semaphore */
|
||||
if (acquire_sem(beos_shm_sem) != B_OK)
|
||||
exit(1); /* Fatal error, exiting with error */
|
||||
}
|
||||
|
||||
void beos_backend_startup_failed(void)
|
||||
void
|
||||
beos_backend_startup_failed(void)
|
||||
{
|
||||
/* The foek failed, just release the semaphore */
|
||||
release_sem(beos_shm_sem);
|
||||
}
|
||||
|
||||
|
||||
void beos_backend_startup(void)
|
||||
void
|
||||
beos_backend_startup(void)
|
||||
{
|
||||
char nom[50];
|
||||
char nvnom[50];
|
||||
area_info inf;
|
||||
int32 cook=0;
|
||||
char nom[50];
|
||||
char nvnom[50];
|
||||
area_info inf;
|
||||
int32 cook = 0;
|
||||
|
||||
/* Perform the remapping process */
|
||||
|
||||
/* Loop in all our team areas */
|
||||
while (get_next_area_info(0, &cook, &inf) == B_OK)
|
||||
{
|
||||
strcpy(nom,inf.name);
|
||||
strcpy(nvnom,inf.name);
|
||||
nom[9]=0;
|
||||
nvnom[5]='i';
|
||||
strcpy(nom, inf.name);
|
||||
strcpy(nvnom, inf.name);
|
||||
nom[9] = 0;
|
||||
nvnom[5] = 'i';
|
||||
/* Is it a SYS V area ? */
|
||||
if (!strcmp(nom,"SYSV_IPC_"))
|
||||
if (!strcmp(nom, "SYSV_IPC_"))
|
||||
{
|
||||
void* area_address;
|
||||
area_id area_postmaster;
|
||||
void *area_address;
|
||||
area_id area_postmaster;
|
||||
|
||||
/* Get the area address */
|
||||
area_address=inf.address;
|
||||
area_address = inf.address;
|
||||
/* Destroy the bad area */
|
||||
delete_area(inf.area);
|
||||
/* Find the postmaster area */
|
||||
area_postmaster=find_area(inf.name);
|
||||
area_postmaster = find_area(inf.name);
|
||||
/* Compute new area name */
|
||||
sprintf(nvnom,"SYSV_IPC %d",area_postmaster);
|
||||
sprintf(nvnom, "SYSV_IPC %d", area_postmaster);
|
||||
/* Clone it at the exact same address */
|
||||
clone_area(nvnom,&area_address,B_CLONE_ADDRESS,B_READ_AREA|B_WRITE_AREA,area_postmaster);
|
||||
clone_area(nvnom, &area_address, B_CLONE_ADDRESS, B_READ_AREA | B_WRITE_AREA, area_postmaster);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* remapping done release semaphore to allow other backend to startup */
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
* System V Semaphore Emulation
|
||||
*
|
||||
* Copyright (c) 1999, repas AEG Automation GmbH
|
||||
*
|
||||
* 2000-12-1 pmb@mac.com
|
||||
* - changed from anonymous to named semaphores for darwin
|
||||
* - this required changing sem_info from containig an array of sem_t to an array of sem_t*
|
||||
*
|
||||
* 2000-12-1 pmb@mac.com
|
||||
* - changed from anonymous to named semaphores for darwin
|
||||
* - this required changing sem_info from containig an array of sem_t to an array of sem_t*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/darwin/Attic/sem.c,v 1.2 2001/01/17 22:11:19 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/darwin/Attic/sem.c,v 1.3 2001/03/22 03:59:42 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -27,13 +27,13 @@
|
||||
#include "storage/proc.h"
|
||||
#include "port/darwin/sem.h"
|
||||
|
||||
#define SEMMAX IPC_NMAXSEM
|
||||
#define SEMMAX IPC_NMAXSEM
|
||||
#define SETMAX ((MAXBACKENDS + SEMMAX - 1) / SEMMAX)
|
||||
#define OPMAX 8
|
||||
|
||||
#define MODE 0700
|
||||
#define SHM_INFO_NAME "SysV_Sem_Info"
|
||||
#define SEM_NAME "/pgsql-darwin"
|
||||
#define SEM_NAME "/pgsql-darwin"
|
||||
|
||||
struct pending_ops
|
||||
{
|
||||
@@ -43,12 +43,12 @@ struct pending_ops
|
||||
|
||||
struct sem_info
|
||||
{
|
||||
sem_t* sem;
|
||||
sem_t *sem;
|
||||
struct
|
||||
{
|
||||
key_t key;
|
||||
int nsems;
|
||||
sem_t* sem[SEMMAX];/* array of POSIX semaphores */
|
||||
sem_t *sem[SEMMAX];/* array of POSIX semaphores */
|
||||
struct sem semV[SEMMAX]; /* array of System V semaphore
|
||||
* structures */
|
||||
struct pending_ops pendingOps[SEMMAX]; /* array of pending
|
||||
@@ -64,12 +64,12 @@ semctl(int semid, int semnum, int cmd, /* ... */ union semun arg)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
sem_wait(SemInfo->sem);
|
||||
sem_wait(SemInfo->sem);
|
||||
|
||||
if (semid < 0 || semid >= SETMAX ||
|
||||
semnum < 0 || semnum >= SemInfo->set[semid].nsems)
|
||||
{
|
||||
sem_post(SemInfo->sem);
|
||||
sem_post(SemInfo->sem);
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ semctl(int semid, int semnum, int cmd, /* ... */ union semun arg)
|
||||
case IPC_RMID:
|
||||
for (semnum = 0; semnum < SemInfo->set[semid].nsems; semnum++)
|
||||
{
|
||||
if (sem_close(SemInfo->set[semid].sem[semnum]) == -1)
|
||||
if (sem_close(SemInfo->set[semid].sem[semnum]) == -1)
|
||||
r = -1;
|
||||
}
|
||||
SemInfo->set[semid].key = -1;
|
||||
@@ -117,12 +117,12 @@ semctl(int semid, int semnum, int cmd, /* ... */ union semun arg)
|
||||
break;
|
||||
|
||||
default:
|
||||
sem_post(SemInfo->sem);
|
||||
sem_post(SemInfo->sem);
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
sem_post(SemInfo->sem);
|
||||
sem_post(SemInfo->sem);
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -134,12 +134,12 @@ semget(key_t key, int nsems, int semflg)
|
||||
semid,
|
||||
semnum /* , semnum1 */ ;
|
||||
int exist = 0;
|
||||
char semname[64];
|
||||
char semname[64];
|
||||
|
||||
if (nsems < 0 || nsems > SEMMAX)
|
||||
{
|
||||
#ifdef DEBUG_IPC
|
||||
fprintf(stderr, "darwin semget aborting because nsems out of range. (%d)\n", nsems);
|
||||
fprintf(stderr, "darwin semget aborting because nsems out of range. (%d)\n", nsems);
|
||||
#endif
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
@@ -149,13 +149,13 @@ semget(key_t key, int nsems, int semflg)
|
||||
if (SemInfo == (struct sem_info *) - 1)
|
||||
{
|
||||
#ifdef DEBUG_IPC
|
||||
fprintf(stderr, "darwin initializing shared mem for semaphore shim.\n");
|
||||
fprintf(stderr, "darwin initializing shared mem for semaphore shim.\n");
|
||||
#endif
|
||||
/* test if the shared memory already exists */
|
||||
fd = shm_open(SHM_INFO_NAME, O_RDWR | O_CREAT | O_EXCL, MODE);
|
||||
if (fd == -1 && errno == EEXIST)
|
||||
{
|
||||
/* exist = 1; */
|
||||
/* exist = 1; */
|
||||
shm_unlink(SHM_INFO_NAME);
|
||||
fd = shm_open(SHM_INFO_NAME, O_RDWR | O_CREAT | O_EXCL, MODE);
|
||||
}
|
||||
@@ -163,7 +163,7 @@ semget(key_t key, int nsems, int semflg)
|
||||
return fd;
|
||||
shm_unlink(SHM_INFO_NAME);
|
||||
/* The size may only be set once. Ignore errors. */
|
||||
ftruncate(fd, sizeof(struct sem_info));
|
||||
ftruncate(fd, sizeof(struct sem_info));
|
||||
SemInfo = mmap(NULL, sizeof(struct sem_info),
|
||||
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (SemInfo == MAP_FAILED)
|
||||
@@ -171,22 +171,22 @@ semget(key_t key, int nsems, int semflg)
|
||||
if (!exist)
|
||||
{
|
||||
/* create semaphore for locking */
|
||||
sprintf(semname, "%s-map", SEM_NAME);
|
||||
sprintf(semname, "%s-map", SEM_NAME);
|
||||
#ifdef DEBUG_IPC
|
||||
fprintf(stderr, "darwin creating sem %s to cover shared mem.\n", semname);
|
||||
fprintf(stderr, "darwin creating sem %s to cover shared mem.\n", semname);
|
||||
#endif
|
||||
SemInfo->sem = sem_open(semname, O_CREAT, semflg & 0777, 1);
|
||||
sem_unlink(semname);
|
||||
sem_wait(SemInfo->sem);
|
||||
SemInfo->sem = sem_open(semname, O_CREAT, semflg & 0777, 1);
|
||||
sem_unlink(semname);
|
||||
sem_wait(SemInfo->sem);
|
||||
/* initilize shared memory */
|
||||
memset(SemInfo->set, 0, sizeof(SemInfo->set));
|
||||
for (semid = 0; semid < SETMAX; semid++)
|
||||
SemInfo->set[semid].key = -1;
|
||||
sem_post(SemInfo->sem);
|
||||
sem_post(SemInfo->sem);
|
||||
}
|
||||
}
|
||||
|
||||
sem_wait(SemInfo->sem);
|
||||
sem_wait(SemInfo->sem);
|
||||
|
||||
if (key != IPC_PRIVATE)
|
||||
{
|
||||
@@ -196,7 +196,7 @@ semget(key_t key, int nsems, int semflg)
|
||||
semid++;
|
||||
if (!(semflg & IPC_CREAT) && semid >= SETMAX)
|
||||
{
|
||||
sem_post(SemInfo->sem);
|
||||
sem_post(SemInfo->sem);
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
@@ -204,7 +204,7 @@ semget(key_t key, int nsems, int semflg)
|
||||
{
|
||||
if (semflg & IPC_CREAT && semflg & IPC_EXCL)
|
||||
{
|
||||
sem_post(SemInfo->sem);
|
||||
sem_post(SemInfo->sem);
|
||||
errno = EEXIST;
|
||||
return -1;
|
||||
}
|
||||
@@ -213,14 +213,14 @@ semget(key_t key, int nsems, int semflg)
|
||||
if (nsems != 0 && SemInfo->set[semid].nsems < nsems)
|
||||
{
|
||||
#ifdef DEBUG_IPC
|
||||
fprintf(stderr, "darwin semget failed because if (nsems != 0 && SemInfo->set[semid].nsems < nsems) %d %d\n",
|
||||
nsems, SemInfo->set[semid].nsems);
|
||||
fprintf(stderr, "darwin semget failed because if (nsems != 0 && SemInfo->set[semid].nsems < nsems) %d %d\n",
|
||||
nsems, SemInfo->set[semid].nsems);
|
||||
#endif
|
||||
sem_post(SemInfo->sem);
|
||||
sem_post(SemInfo->sem);
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
sem_post(SemInfo->sem);
|
||||
sem_post(SemInfo->sem);
|
||||
return semid;
|
||||
}
|
||||
}
|
||||
@@ -233,28 +233,28 @@ fprintf(stderr, "darwin semget failed because if (nsems != 0 && SemInfo->set[sem
|
||||
if (semid >= SETMAX)
|
||||
{
|
||||
#ifdef DEBUG_IPC
|
||||
fprintf(stderr, "darwin semget failed because all keys were -1 up to SETMAX\n");
|
||||
fprintf(stderr, "darwin semget failed because all keys were -1 up to SETMAX\n");
|
||||
#endif
|
||||
sem_post(SemInfo->sem);
|
||||
sem_post(SemInfo->sem);
|
||||
errno = ENOSPC;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (semnum = 0; semnum < nsems; semnum++)
|
||||
{
|
||||
sprintf(semname, "%s-%d-%d", SEM_NAME, semid, semnum);
|
||||
sprintf(semname, "%s-%d-%d", SEM_NAME, semid, semnum);
|
||||
#ifdef DEBUG_IPC
|
||||
fprintf(stderr, "darwin creating sem %s to cover set %d num %dm.\n", semname, semid, semnum);
|
||||
fprintf(stderr, "darwin creating sem %s to cover set %d num %dm.\n", semname, semid, semnum);
|
||||
#endif
|
||||
SemInfo->set[semid].sem[semnum] = sem_open(semname, O_CREAT, semflg & 0777, 0);
|
||||
sem_unlink(semname);
|
||||
SemInfo->set[semid].sem[semnum] = sem_open(semname, O_CREAT, semflg & 0777, 0);
|
||||
sem_unlink(semname);
|
||||
|
||||
/* Currently sem_init always returns -1.
|
||||
if( sem_init( &SemInfo->set[semid].sem[semnum], 1, 0 ) == -1 ) {
|
||||
for( semnum1 = 0; semnum1 < semnum; semnum1++ ) {
|
||||
sem_close( SemInfo->set[semid].sem[semnum1] );
|
||||
sem_close( SemInfo->set[semid].sem[semnum1] );
|
||||
}
|
||||
sem_post( SemInfo->sem );
|
||||
sem_post( SemInfo->sem );
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
@@ -263,7 +263,7 @@ fprintf(stderr, "darwin semget failed because if (nsems != 0 && SemInfo->set[sem
|
||||
SemInfo->set[semid].key = key;
|
||||
SemInfo->set[semid].nsems = nsems;
|
||||
|
||||
sem_post(SemInfo->sem);
|
||||
sem_post(SemInfo->sem);
|
||||
|
||||
return semid;
|
||||
}
|
||||
@@ -277,11 +277,11 @@ semop(int semid, struct sembuf * sops, size_t nsops)
|
||||
errno1 = 0,
|
||||
op;
|
||||
|
||||
sem_wait(SemInfo->sem);
|
||||
sem_wait(SemInfo->sem);
|
||||
|
||||
if (semid < 0 || semid >= SETMAX)
|
||||
{
|
||||
sem_post(SemInfo->sem);
|
||||
sem_post(SemInfo->sem);
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
@@ -289,7 +289,7 @@ semop(int semid, struct sembuf * sops, size_t nsops)
|
||||
{
|
||||
if ( /* sops[i].sem_num < 0 || */ sops[i].sem_num >= SemInfo->set[semid].nsems)
|
||||
{
|
||||
sem_post(SemInfo->sem);
|
||||
sem_post(SemInfo->sem);
|
||||
errno = EFBIG;
|
||||
return -1;
|
||||
}
|
||||
@@ -303,7 +303,7 @@ semop(int semid, struct sembuf * sops, size_t nsops)
|
||||
{
|
||||
if (sops[i].sem_flg & IPC_NOWAIT)
|
||||
{
|
||||
sem_post(SemInfo->sem);
|
||||
sem_post(SemInfo->sem);
|
||||
errno = EAGAIN;
|
||||
return -1;
|
||||
}
|
||||
@@ -311,15 +311,15 @@ semop(int semid, struct sembuf * sops, size_t nsops)
|
||||
if (SemInfo->set[semid].pendingOps[sops[i].sem_num].idx >= OPMAX)
|
||||
{
|
||||
/* pending operations array overflow */
|
||||
sem_post(SemInfo->sem);
|
||||
sem_post(SemInfo->sem);
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
SemInfo->set[semid].pendingOps[sops[i].sem_num].op[SemInfo->set[semid].pendingOps[sops[i].sem_num].idx++] = sops[i].sem_op;
|
||||
/* suspend */
|
||||
sem_post(SemInfo->sem); /* avoid deadlock */
|
||||
r1 = sem_wait(SemInfo->set[semid].sem[sops[i].sem_num]);
|
||||
sem_wait(SemInfo->sem);
|
||||
sem_post(SemInfo->sem); /* avoid deadlock */
|
||||
r1 = sem_wait(SemInfo->set[semid].sem[sops[i].sem_num]);
|
||||
sem_wait(SemInfo->sem);
|
||||
if (r1)
|
||||
{
|
||||
errno1 = errno;
|
||||
@@ -343,7 +343,7 @@ semop(int semid, struct sembuf * sops, size_t nsops)
|
||||
if (SemInfo->set[semid].pendingOps[sops[i].sem_num].op[SemInfo->set[semid].pendingOps[sops[i].sem_num].idx - 1] + op >= 0)
|
||||
{
|
||||
/* unsuspend processes */
|
||||
if (sem_post(SemInfo->set[semid].sem[sops[i].sem_num]))
|
||||
if (sem_post(SemInfo->set[semid].sem[sops[i].sem_num]))
|
||||
{
|
||||
errno1 = errno;
|
||||
r = -1;
|
||||
@@ -364,14 +364,14 @@ semop(int semid, struct sembuf * sops, size_t nsops)
|
||||
/* sops[i].sem_op == 0 */
|
||||
{
|
||||
/* not supported */
|
||||
sem_post(SemInfo->sem);
|
||||
sem_post(SemInfo->sem);
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
SemInfo->set[semid].semV[sops[i].sem_num].sempid = getpid();
|
||||
}
|
||||
|
||||
sem_post(SemInfo->sem);
|
||||
sem_post(SemInfo->sem);
|
||||
|
||||
errno = errno1;
|
||||
return r;
|
||||
|
||||
@@ -609,4 +609,4 @@ findMain(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* HAVE_DLOPEN */
|
||||
#endif /* HAVE_DLOPEN */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: aix.h,v 1.4 2001/02/10 02:31:26 tgl Exp $
|
||||
* $Id: aix.h,v 1.5 2001/03/22 03:59:42 momjian Exp $
|
||||
*
|
||||
* @(#)dlfcn.h 1.4 revision of 95/04/25 09:36:52
|
||||
* This is an unpublished work copyright (c) 1992 HELIOS Software GmbH
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#else /* HAVE_DLOPEN */
|
||||
#else /* HAVE_DLOPEN */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
@@ -54,13 +54,13 @@ extern "C"
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_DLOPEN */
|
||||
#endif /* HAVE_DLOPEN */
|
||||
|
||||
#include "utils/dynamic_loader.h"
|
||||
|
||||
#define pg_dlopen(f) dlopen(f, RTLD_LAZY)
|
||||
#define pg_dlsym dlsym
|
||||
#define pg_dlclose dlclose
|
||||
#define pg_dlerror dlerror
|
||||
#define pg_dlclose dlclose
|
||||
#define pg_dlerror dlerror
|
||||
|
||||
#endif /* PORT_PROTOS_H */
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/Attic/beos.c,v 1.6 2001/02/10 02:31:26 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/Attic/beos.c,v 1.7 2001/03/22 03:59:42 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -18,59 +18,66 @@
|
||||
#include "utils/dynamic_loader.h"
|
||||
|
||||
|
||||
void *
|
||||
void *
|
||||
pg_dlopen(char *filename)
|
||||
{
|
||||
image_id* im;
|
||||
|
||||
/* Handle memory allocation to store the Id of the shared object*/
|
||||
im=(image_id*)(malloc(sizeof(image_id)));
|
||||
|
||||
image_id *im;
|
||||
|
||||
/* Handle memory allocation to store the Id of the shared object */
|
||||
im = (image_id *) (malloc(sizeof(image_id)));
|
||||
|
||||
/* Add-on loading */
|
||||
*im=beos_dl_open(filename);
|
||||
|
||||
*im = beos_dl_open(filename);
|
||||
|
||||
return im;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
char *
|
||||
pg_dlerror()
|
||||
{
|
||||
static char errmsg[] = "Load Add-On failed";
|
||||
|
||||
return errmsg;
|
||||
}
|
||||
|
||||
PGFunction
|
||||
PGFunction
|
||||
pg_dlsym(void *handle, char *funcname)
|
||||
{
|
||||
PGFunction fpt;
|
||||
PGFunction fpt;
|
||||
|
||||
/* Checking that "Handle" is valid */
|
||||
if ((handle) && ((*(int*)(handle))>=0))
|
||||
if ((handle) && ((*(int *) (handle)) >= 0))
|
||||
{
|
||||
/* Loading symbol */
|
||||
if(get_image_symbol(*((int*)(handle)),funcname,B_SYMBOL_TYPE_TEXT,(void**)&fpt)==B_OK);
|
||||
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) || (fpt>=(info.text+info.text_size))) return NULL;
|
||||
|
||||
/*
|
||||
* 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) ||(fpt >= (info.text +info.text_size)))
|
||||
return NULL;
|
||||
return fpt;
|
||||
}
|
||||
elog(NOTICE, "loading symbol '%s' failed ",funcname);
|
||||
elog(NOTICE, "loading symbol '%s' failed ", funcname);
|
||||
}
|
||||
elog(NOTICE, "add-on not loaded correctly");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
pg_dlclose(void *handle)
|
||||
{
|
||||
/* Checking that "Handle" is valid */
|
||||
if ((handle) && ((*(int*)(handle))>=0))
|
||||
if ((handle) && ((*(int *) (handle)) >= 0))
|
||||
{
|
||||
if (beos_dl_close(*(image_id*)handle)!=B_OK)
|
||||
if (beos_dl_close(*(image_id *) handle) != B_OK)
|
||||
elog(NOTICE, "error while unloading add-on");
|
||||
free(handle);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
/*
|
||||
* These routines were taken from the Apache source, but were made
|
||||
* available with a PostgreSQL-compatible license. Kudos Wilfredo
|
||||
* available with a PostgreSQL-compatible license. Kudos Wilfredo
|
||||
* S<>nchez <wsanchez@apple.com>.
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/darwin.c,v 1.4 2000/12/11 00:49:54 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/darwin.c,v 1.5 2001/03/22 03:59:42 momjian Exp $
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
#include <mach-o/dyld.h>
|
||||
#include "dynloader.h"
|
||||
|
||||
void *pg_dlopen(char *filename)
|
||||
void *
|
||||
pg_dlopen(char *filename)
|
||||
{
|
||||
NSObjectFileImage image;
|
||||
|
||||
@@ -20,16 +21,18 @@ void *pg_dlopen(char *filename)
|
||||
return NSLinkModule(image, filename, TRUE);
|
||||
}
|
||||
|
||||
void pg_dlclose(void *handle)
|
||||
void
|
||||
pg_dlclose(void *handle)
|
||||
{
|
||||
NSUnLinkModule(handle,FALSE);
|
||||
NSUnLinkModule(handle, FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
PGFunction pg_dlsym(void *handle, char *funcname)
|
||||
PGFunction
|
||||
pg_dlsym(void *handle, char *funcname)
|
||||
{
|
||||
NSSymbol symbol;
|
||||
char *symname = (char*)malloc(strlen(funcname)+2);
|
||||
NSSymbol symbol;
|
||||
char *symname = (char *) malloc(strlen(funcname) + 2);
|
||||
|
||||
sprintf(symname, "_%s", funcname);
|
||||
if (NSIsSymbolNameDefined(symname))
|
||||
@@ -41,11 +44,12 @@ PGFunction pg_dlsym(void *handle, char *funcname)
|
||||
else
|
||||
{
|
||||
free(symname);
|
||||
return (PGFunction)NULL;
|
||||
return (PGFunction) NULL;
|
||||
}
|
||||
}
|
||||
|
||||
char *pg_dlerror(void)
|
||||
char *
|
||||
pg_dlerror(void)
|
||||
{
|
||||
return "no error message available";
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* $Header: /cvsroot/pgsql/src/backend/port/dynloader/darwin.h,v 1.3 2000/12/11 00:49:54 tgl Exp $ */
|
||||
/* $Header: /cvsroot/pgsql/src/backend/port/dynloader/darwin.h,v 1.4 2001/03/22 03:59:42 momjian Exp $ */
|
||||
|
||||
#include "fmgr.h"
|
||||
|
||||
void* pg_dlopen(char *filename);
|
||||
void *pg_dlopen(char *filename);
|
||||
PGFunction pg_dlsym(void *handle, char *funcname);
|
||||
void pg_dlclose(void *handle);
|
||||
char* pg_dlerror(void);
|
||||
char *pg_dlerror(void);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/hpux.c,v 1.17 2001/02/10 02:31:26 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/hpux.c,v 1.18 2001/03/22 03:59:43 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* all functions are defined here -- it's impossible to trace the
|
||||
@@ -28,13 +28,14 @@
|
||||
void *
|
||||
pg_dlopen(char *filename)
|
||||
{
|
||||
|
||||
/*
|
||||
* Use BIND_IMMEDIATE so that undefined symbols cause a failure return
|
||||
* from shl_load(), rather than an abort() later on when we attempt to
|
||||
* call the library!
|
||||
*/
|
||||
shl_t handle = shl_load(filename,
|
||||
BIND_IMMEDIATE | BIND_VERBOSE | DYNAMIC_PATH,
|
||||
BIND_IMMEDIATE | BIND_VERBOSE | DYNAMIC_PATH,
|
||||
0L);
|
||||
|
||||
return (void *) handle;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $Header: /cvsroot/pgsql/src/backend/port/dynloader/solaris.h,v 1.2 2001/02/10 02:31:26 tgl Exp $ */
|
||||
/* $Header: /cvsroot/pgsql/src/backend/port/dynloader/solaris.h,v 1.3 2001/03/22 03:59:43 momjian Exp $ */
|
||||
|
||||
#ifndef DYNLOADER_SOLARIS_H
|
||||
#define DYNLOADER_SOLARIS_H
|
||||
@@ -11,4 +11,4 @@
|
||||
#define pg_dlclose dlclose
|
||||
#define pg_dlerror dlerror
|
||||
|
||||
#endif /* DYNLOADER_SOLARIS_H */
|
||||
#endif /* DYNLOADER_SOLARIS_H */
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/qnx4/Attic/shm.c,v 1.3 2001/03/13 01:17:06 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/port/qnx4/Attic/shm.c,v 1.4 2001/03/22 03:59:43 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -184,8 +184,10 @@ shmctl(int shmid, int cmd, struct shmid_ds * buf)
|
||||
}
|
||||
if (cmd == IPC_STAT)
|
||||
{
|
||||
/* Can we support IPC_STAT? We only need shm_nattch ...
|
||||
* For now, punt and assume the shm seg does not exist.
|
||||
|
||||
/*
|
||||
* Can we support IPC_STAT? We only need shm_nattch ... For now,
|
||||
* punt and assume the shm seg does not exist.
|
||||
*/
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
|
||||
@@ -109,7 +109,7 @@ int base;
|
||||
cutoff = neg ? -(unsigned long) LONG_MIN : LONG_MAX;
|
||||
cutlim = cutoff % (unsigned long) base;
|
||||
cutoff /= (unsigned long) base;
|
||||
for (acc = 0, any = 0; ; c = *s++)
|
||||
for (acc = 0, any = 0;; c = *s++)
|
||||
{
|
||||
if (isdigit(c))
|
||||
c -= '0';
|
||||
|
||||
Reference in New Issue
Block a user