Silly error with flock

Mike Krogh krogh at talon.ncsa.uiuc.edu
Fri Jan 11 08:40:11 AEST 1991


Make sure that 'lockd' and 'statd' are running on your machine (see 
'man lockd') for info.

There also exists a more serious error with file locking, which may affect
your Email (and possibly other things).

If you set a lock on a file that exists on an NFS partition and that file
goes to zero in size, then the file will appear to contain garbage from 
then on.  To solve the problem, you must either delete the file or reboot
the machine.  The file will appear to be correct on other machines, so the
file is not actually corrupted, just its appearance.

I first encountered this bug after deleting my new mail in 'mbox', which
is on our server.  'mbox' then appears to be corrupted from then on.  The
temporary solution has been to read my mail on a Sun workstation.

In article <1991Jan9.030948.18665 at ccu1.aukuni.ac.nz>, russell at ccu1.aukuni.ac.nz (Russell J Fulton;ccc032u) writes:
> I am trying to use flock but I always get an "Bad file number" error.
> Here is my test program:
> 
> #include <sys/types.h>
> #include <sys/file.h>
> #include <stdio.h>
> 
> main() {
>     int lock;
> 
>     lock = open("test.lock",O_RDONLY); /* test.lock does exist */
>     if ( lock <= 0) perror("open");
> 
>     if(flock(lock,LOCK_EX) == -1) perror("flock");
> 
>     getchar();
>     flock(lock,LOCK_UN);
>     close (lock);
> }
> 
> Always prints "flock: Bad file number"!
> 
> Any ideas?? It must be something so obvious that I have totally missed it!
> 
> Cheers, Russell.
> -- 
> Russell Fulton, Computer Center, University of Auckland, New Zealand.
> <rj_fulton at aukuni.ac.nz>



More information about the Comp.sys.sgi mailing list