Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1f159e5

Browse files
committed
>> 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 thatthe>> loader sometime return OK with an invalid symbol)>> postmaster.c : add beos forking support for the new checkpointprocess>> postgres.c : remove beos special case for getrusage>> beos.h : Correction of a bas definition of AF_UNIX, misc defnitions>>>>>> thanks>>>>>> cyrilCyril VELTER
1 parent5491233 commit1f159e5

File tree

6 files changed

+110
-25
lines changed

6 files changed

+110
-25
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.43 2000/12/1800:44:45 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.44 2000/12/1818:45:03 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -874,7 +874,11 @@ XLogFileInit(uint32 log, uint32 seg, bool *usexistent)
874874

875875
close(fd);
876876

877+
#ifndef__BEOS__
877878
if (link(tpath,path)<0)
879+
#else
880+
if (rename(tpath,path)<0)
881+
#endif
878882
elog(STOP,"InitRelink(logfile %u seg %u) failed: %m",
879883
logId,logSeg);
880884

‎src/backend/port/beos/sem.c

Lines changed: 71 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,20 @@
1212
#include"postgres.h"
1313
#include<stdio.h>
1414
#include<errno.h>
15+
#include<unistd.h>
1516
#include<OS.h>
1617
#include"utils/elog.h"
1718

19+
/*#define TDBG*/
20+
#ifdefTDBG
21+
#defineTRACEDBG(x) printf(x);printf("\n")
22+
#defineTRACEDBGP(x,y) printf(x,y);printf("\n")
23+
#defineTRACEDBGPP(x,y,z) printf(x,y,z);printf("\n")
24+
#else
25+
#defineTRACEDBG(x)
26+
#defineTRACEDBGP(x,y)
27+
#defineTRACEDBGPP(x,y,z)
28+
#endif
1829

1930
/* Control of a semaphore pool. The pool is an area in which we stored all
2031
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)
2536
int32*Address;
2637
area_infoinfo;
2738

39+
TRACEDBG("->semctl");
2840
/* Try to find the pool */
2941
if (get_area_info(semId,&info)!=B_OK)
3042
{
3143
/* pool is invalid (BeOS area id is invalid) */
3244
errno=EINVAL;
45+
TRACEDBG("<-semctl invalid pool");
3346
return-1;
3447
}
3548

3649
/* Get the pool address */
3750
Address=(int32*)info.address;
51+
TRACEDBGP("--semctl address %d",Address);
3852

3953

4054
/* semNum might be 0 */
@@ -44,18 +58,22 @@ int semctl(int semId,int semNum,int flag,union semun semun)
4458
if (flag==SETALL)
4559
{
4660
longi;
61+
TRACEDBG("--semctl setall");
4762
for (i=0;i<Address[0];i++)
4863
{
4964
int32cnt;
5065
/* Get the current count */
51-
get_sem_count(Address[i+1],&cnt);
66+
get_sem_count(Address[2*i+1],&cnt);
67+
68+
TRACEDBGP("--semctl setall %d",semun.array[i]);
5269

5370
/* Compute and set the new count (relative to the old one) */
5471
cnt-=semun.array[i];
72+
TRACEDBGPP("--semctl acquire id : %d cnt : %d",Address[2*i+1],cnt);
5573
if (cnt>0)
56-
while(acquire_sem_etc(Address[i+1],cnt,0,0)==B_INTERRUPTED);
74+
while(acquire_sem_etc(Address[2*i+1],cnt,0,0)==B_INTERRUPTED);
5775
if (cnt<0)
58-
release_sem_etc(Address[i+1],-cnt,0);
76+
release_sem_etc(Address[2*i+1],-cnt,0);
5977
}
6078
return1;
6179
}
@@ -64,37 +82,49 @@ int semctl(int semId,int semNum,int flag,union semun semun)
6482
if (flag==SETVAL)
6583
{
6684
int32cnt;
85+
TRACEDBGP("--semctl setval %d",semun.val);
6786
/* Get the current count */
68-
get_sem_count(Address[semNum+1],&cnt);
87+
get_sem_count(Address[2*semNum+1],&cnt);
6988

7089
/* Compute and set the new count (relative to the old one) */
7190
cnt-=semun.val;
91+
TRACEDBGPP("--semctl acquire id : %d cnt : %d",Address[2*semNum+1],cnt);
7292
if (cnt>0)
73-
while(acquire_sem_etc(Address[semNum+1],cnt,0,0)==B_INTERRUPTED);
93+
while(acquire_sem_etc(Address[2*semNum+1],cnt,0,0)==B_INTERRUPTED);
7494
if (cnt<0)
75-
release_sem_etc(Address[semNum+1],-cnt,0);
95+
release_sem_etc(Address[2*semNum+1],-cnt,0);
7696
return1;
7797
}
7898

99+
/* Get the last pid which accesed the sem */
100+
if (flag==GETPID)
101+
{
102+
TRACEDBG("->semctl getpid");
103+
returnAddress[2*semNum+2];
104+
}
105+
79106
/* Delete the pool */
80107
if (flag==IPC_RMID)
81108
{
82109
longi;
83110

84111
thread_infoti;
112+
TRACEDBG("->semctl rmid");
85113
get_thread_info(find_thread(NULL),&ti);
86114

87115
/* Loop over all semaphore to delete them */
116+
TRACEDBGP("->semctl nmbre %d",Address[0]);
88117
for (i=0;i<Address[0];i++)
89118
{
90-
/* Don't remember why I do that */
91-
set_sem_owner(Address[i+1],ti.team);
119+
/* Make sure to have ownership of the semaphore (if created by another team) */
120+
TRACEDBGP("->semctl id %d",Address[2*i+1]);
121+
set_sem_owner(Address[2*i+1],ti.team);
92122

93123
/* Delete the semaphore */
94-
delete_sem(Address[i+1]);
124+
delete_sem(Address[2*i+1]);
95125

96126
/* Reset to an invalid semId (in case other process try to get the infos from a cloned area */
97-
Address[i+1]=0;
127+
Address[2*i+1]=0;
98128
}
99129

100130
/* Set the semaphore count to 0 */
@@ -111,6 +141,7 @@ int semctl(int semId,int semNum,int flag,union semun semun)
111141
if (flag==GETNCNT)
112142
{
113143
/* TO BE IMPLEMENTED */
144+
TRACEDBG("--semctl getncnt");
114145
elog(ERROR,"beos : semctl error : GETNCNT not implemented");
115146
return0;
116147
}
@@ -119,12 +150,15 @@ int semctl(int semId,int semNum,int flag,union semun semun)
119150
if (flag==GETVAL)
120151
{
121152
int32cnt;
122-
get_sem_count(Address[semNum+1],&cnt);
153+
TRACEDBG("--semctl getval");
154+
get_sem_count(Address[2*semNum+1],&cnt);
155+
TRACEDBGP("--semctl val %d",cnt);
123156
returncnt;
124157
}
125158

126159
elog(ERROR,"beos : semctl error : unknown flag");
127160

161+
TRACEDBG("<-semctl unknown flag");
128162
return0;
129163
}
130164

@@ -135,6 +169,7 @@ int semget(int semKey, int semNum, int flags)
135169
area_idparea;
136170
void*Address;
137171

172+
TRACEDBGPP("->semget key : %d num : %d",semKey,semNum);
138173
/* Name of the area to find */
139174
sprintf(Nom,"SYSV_IPC_SEM : %d",semKey);
140175

@@ -165,8 +200,9 @@ int semget(int semKey, int semNum, int flags)
165200
void*Ad;
166201
longi;
167202

168-
/* Limit to 500 semaphore in a pool */
169-
if (semNum>500)
203+
/* Limit to 250 (8 byte per sem : 4 for the semid and 4 for the last pid
204+
which acceced the semaphore in a pool */
205+
if (semNum>250)
170206
{
171207
errno=ENOSPC;
172208
return-1;
@@ -183,12 +219,12 @@ int semget(int semKey, int semNum, int flags)
183219
/* fill up informations (sem number and sem ids) */
184220
Address=(int32*)Ad;
185221
Address[0]=semNum;
186-
for (i=1;i<=Address[0];i++)
222+
for (i=0;i<Address[0];i++)
187223
{
188224
/* Create the semaphores */
189-
Address[i]=create_sem(0,Nom);
225+
Address[2*i+1]=create_sem(0,Nom);
190226

191-
if ((Address[i]==B_BAD_VALUE)|| (Address[i]==B_NO_MEMORY)||(Address[i]==B_NO_MORE_SEMS))
227+
if ((Address[2*i+1]==B_BAD_VALUE)|| (Address[2*i+1]==B_NO_MEMORY)||(Address[2*i+1]==B_NO_MORE_SEMS))
192228
{
193229
errno=ENOMEM;
194230
return-1;
@@ -212,6 +248,7 @@ int semop(int semId, struct sembuf *sops, int nsops)
212248
int32*Address;/*Pool address*/
213249
area_infoinfo;
214250
longi;
251+
longret;
215252

216253
/* Get the pool address (semId IS an area id) */
217254
get_area_info(semId,&info);
@@ -227,16 +264,32 @@ int semop(int semId, struct sembuf *sops, int nsops)
227264
/* Perform acquire or release */
228265
for(i=0;i<nsops;i++)
229266
{
267+
/* remember the PID */
268+
Address[2*(sops[i].sem_num)+2]=getpid();
269+
230270
/* For each sem in the pool, check the operation to perform */
231271
if (sops[i].sem_op<0)
232272
{
233273
/* Try acuiring the semaphore till we are not inteerupted by a signal */
234-
while (acquire_sem_etc(Address[sops[i].sem_num+1],-sops[i].sem_op,0,0)==B_INTERRUPTED);
274+
if (sops[i].sem_flg==IPC_NOWAIT)
275+
{
276+
/* Try to lock ... */
277+
while ((ret=acquire_sem_etc(Address[2*(sops[i].sem_num)+1],-sops[i].sem_op,B_RELATIVE_TIMEOUT,0))==B_INTERRUPTED);
278+
if (ret!=B_OK)
279+
{
280+
returnEWOULDBLOCK;
281+
}
282+
}
283+
else
284+
{
285+
while (acquire_sem_etc(Address[2*(sops[i].sem_num)+1],-sops[i].sem_op,0,0)==B_INTERRUPTED);
286+
}
235287
}
236288
if (sops[i].sem_op>0)
237289
{
238-
release_sem_etc(Address[sops[i].sem_num+1],sops[i].sem_op,0);
290+
release_sem_etc(Address[2*(sops[i].sem_num)+1],sops[i].sem_op,0);
239291
}
240292
}
293+
241294
return0;
242295
}

‎src/backend/port/dynloader/beos.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/Attic/beos.c,v 1.3 2000/10/07 14:39:11 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/port/dynloader/Attic/beos.c,v 1.4 2000/12/18 18:45:04 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -51,6 +51,11 @@ pg_dlsym(void *handle, char *funcname)
5151
/* Loading symbol */
5252
if(get_image_symbol(*((int*)(handle)),funcname,B_SYMBOL_TYPE_TEXT,(void**)&fpt)==B_OK);
5353
{
54+
/* Sometime the loader return B_OK for an inexistant function with an invalid address !!!
55+
Check that the return address is in the image range */
56+
image_infoinfo;
57+
get_image_info(*((int*)(handle)),&info);
58+
if ((fpt<info.text)|| (fpt>=(info.text+info.text_size)))returnNULL;
5459
returnfpt;
5560
}
5661
elog(NOTICE,"loading symbol '%s' failed ",funcname);

‎src/backend/postmaster/postmaster.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.199 2000/12/1817:33:40 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.200 2000/12/1818:45:04 momjian Exp $
1515
*
1616
* NOTES
1717
*
@@ -2181,6 +2181,11 @@ SSDataBase(int xlop)
21812181
fflush(stdout);
21822182
fflush(stderr);
21832183

2184+
#ifdef__BEOS__
2185+
/* Specific beos actions before backend startup */
2186+
beos_before_backend_startup();
2187+
#endif
2188+
21842189
if ((pid=fork())==0)/* child */
21852190
{
21862191
char*av[ARGV_SIZE*2];
@@ -2189,6 +2194,11 @@ SSDataBase(int xlop)
21892194
chardbbuf[ARGV_SIZE];
21902195
charxlbuf[ARGV_SIZE];
21912196

2197+
#ifdef__BEOS__
2198+
/* Specific beos actions after backend startup */
2199+
beos_backend_startup();
2200+
#endif
2201+
21922202
/* Lose the postmaster's on-exit routines and port connections */
21932203
on_exit_reset();
21942204

@@ -2234,6 +2244,11 @@ SSDataBase(int xlop)
22342244
/* in parent */
22352245
if (pid<0)
22362246
{
2247+
#ifdef__BEOS__
2248+
/* Specific beos actions before backend startup */
2249+
beos_backend_startup_failed();
2250+
#endif
2251+
22372252
fprintf(stderr,"%s Data Base: fork failed: %s\n",
22382253
((xlop==BS_XLOG_STARTUP) ?"Startup" :
22392254
((xlop==BS_XLOG_CHECKPOINT) ?"CheckPoint" :

‎src/backend/tcop/postgres.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.196 2000/12/1817:33:41 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.197 2000/12/1818:45:05 momjian Exp $
1212
*
1313
* NOTES
1414
* 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
16491649
if (!IsUnderPostmaster)
16501650
{
16511651
puts("\nPOSTGRES backend interactive interface ");
1652-
puts("$Revision: 1.196 $ $Date: 2000/12/1817:33:41 $\n");
1652+
puts("$Revision: 1.197 $ $Date: 2000/12/1818:45:05 $\n");
16531653
}
16541654

16551655
/*
@@ -1950,7 +1950,7 @@ ShowUsage(void)
19501950
(longint)sys.tv_sec,
19511951
(longint)sys.tv_usec);
19521952
/* BeOS has rusage but only has some fields, and not these... */
1953-
#if defined(HAVE_GETRUSAGE)&& !defined(__BEOS__)
1953+
#if defined(HAVE_GETRUSAGE)
19541954
fprintf(StatFp,
19551955
"!\t%ld/%ld [%ld/%ld] filesystem blocks in/out\n",
19561956
r.ru_inblock-Save_r.ru_inblock,

‎src/include/port/beos.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55

66
typedefunsignedcharslock_t;
77

8-
#defineAF_UNIX 1/* no domain sockets on BeOS */
8+
#defineAF_UNIX 10/* no domain sockets on BeOS */
9+
10+
/* Beos doesn't have sysnerr but strerror should works on every error */
11+
externintsys_nerr;
12+
13+
/* Beos doesn't have all the required getrusage fields */
14+
#undef HAVE_GETRUSAGE
915

1016
/* SYS V emulation */
1117

@@ -16,6 +22,7 @@ typedef unsigned char slock_t;
1622
#defineIPC_CREAT 512
1723
#defineIPC_EXCL 1024
1824
#defineIPC_PRIVATE 234564
25+
#defineIPC_NOWAIT2048
1926

2027
#defineEACCESS 2048
2128
#defineEIDRM 4096
@@ -24,6 +31,7 @@ typedef unsigned char slock_t;
2431
#defineGETNCNT 16384
2532
#defineGETVAL 65536
2633
#defineSETVAL 131072
34+
#defineGETPID 262144
2735

2836
unionsemun
2937
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp