I'm trying to write two C language user defined functions, lockfile() and
unlockfile(), that call flock using LOCK_EX and LOCK_UN respectively. If I
call lockfile from a first psql process it returns successfully. Calling
lockfile from a second psql process blocks. However, when I call unlockfile
from the first psql process, the second process still blocks. The lockfile
call from the second psql proccess doesn't return until I kill the first
psql process.
Any suggestions? Thanks in advance.
Chris Goughnour
PG_FUNCTION_INF O_V1(lockFile);
Datum lockFile(PG_FUN CTION_ARGS){
text *t=PG_GETARG_TE XT_P(0);
char *path=palloc(VA RSIZE(t)-VARHDRSZ+1);
int fileHandle,stat us;
memcpy((void *)path,(void *)VARDATA(t),VA RSIZE(t)-VARHDRSZ);
path[VARSIZE(t)-VARHDRSZ]=0;
fileHandle=open ((const char *)path,O_RDONLY );
if(fileHandle==-1){
PG_RETURN_INT32 (-1);
}
if(flock(fileHa ndle,LOCK_EX)==-1){
PG_RETURN_INT32 (-1);
}
PG_RETURN_INT32 (0);
}
PG_FUNCTION_INF O_V1(unlockFile );
Datum unlockFile(PG_F UNCTION_ARGS){
text *t=PG_GETARG_TE XT_P(0);
char *path=palloc(VA RSIZE(t)-VARHDRSZ+1);
int fileHandle;
memcpy((void *)path,(void *)VARDATA(t),VA RSIZE(t)-VARHDRSZ);
path[VARSIZE(t)-VARHDRSZ]=0;
fileHandle=open ((const char *)path,O_RDONLY );
if(fileHandle==-1){
PG_RETURN_INT32 (-1);
}
if(flock(fileHa ndle,LOCK_UN)==-1){
PG_RETURN_INT32 (-1);
}
PG_RETURN_INT32 (0);
}
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly