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_INFO_V1(lockFile); Datum lockFile(PG_FUNCTION_ARGS){ text *t=PG_GETARG_TEXT_P(0); char *path=palloc(VARSIZE(t)-VARHDRSZ+1); int fileHandle,status; memcpy((void *)path,(void *)VARDATA(t),VARSIZE(t)-VARHDRSZ); path[VARSIZE(t)-VARHDRSZ]=0; fileHandle=open((const char *)path,O_RDONLY); if(fileHandle==-1){ PG_RETURN_INT32(-1); } if(flock(fileHandle,LOCK_EX)==-1){ PG_RETURN_INT32(-1); } PG_RETURN_INT32(0); } PG_FUNCTION_INFO_V1(unlockFile); Datum unlockFile(PG_FUNCTION_ARGS){ text *t=PG_GETARG_TEXT_P(0); char *path=palloc(VARSIZE(t)-VARHDRSZ+1); int fileHandle; memcpy((void *)path,(void *)VARDATA(t),VARSIZE(t)-VARHDRSZ); path[VARSIZE(t)-VARHDRSZ]=0; fileHandle=open((const char *)path,O_RDONLY); if(fileHandle==-1){ PG_RETURN_INT32(-1); } if(flock(fileHandle,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 [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly