Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!mailrus!csd4.milw.wisc.edu!dogie.macc.wisc.edu!indri!bin From: bin@primate.wisc.edu (Brain in Neutral) Newsgroups: comp.sys.mips Subject: flock(2) doesn't return EWOULDBLOCK Message-ID: <448@indri.primate.wisc.edu> Date: 24 Jul 89 16:59:02 GMT Organization: UW-Madison Primate Center Lines: 66 Synopsis: flock does not return EWOULDBLOCK as advertised. Description: flock is supposed to return EWOULDBLOCK when trying to acquire an exclusive lock on an open file descriptor and the "don't block" flag is specified. It doesn't, it returns EACCES "Permission denied" instead. This can be seen by compiling the code below and running two instances of it simultaneously. # include # include main () { extern int errno; int f; f = open ("junk", O_WRONLY|O_CREAT, 0644); if (f < 0) { perror ("f open"); exit (1); } printf ("f opened\n"); if (flock (f, LOCK_EX|LOCK_NB) < 0) { if (errno == EWOULDBLOCK) { perror ("f flock1"); exit (1); } perror ("f flock2"); exit(1); } printf ("f locked\n"); sleep (10); } The first instance prints: f opened f locked The second instance prints: f opened f flock2: Permission denied This is not only wrong, but EACCES is not one of the possible error returns mentioned in the man page. Package/Version: OS: RISC/os 4.0 Configuration: MIPS M/120, 16MB, 2 328MB disks, cartridge tape, etc. Suggested workaround: Do if (errno == EWOULDBLOCK || errno == EACCES) instead of if (errno == EWOULDBLOCK) Of course this is ugly and shouldn't have to be done.