flock brokenness

Jim Wilcoxson (jim@meritnet.com)
Mon, 13 Jul 1998 18:02:58 -0400


I'm having trouble getting flock to work with 2.0.34pre16. Here's the test
program I'm using. Works great on a Dec Alpha, but on Linux it lets
multiple writers in, i.e., no errors, but no locking either. I'm running
the standard glibc2.0.5 that came with RedHat; can't update to 2.0.7 'cause
I have multithread software that bombs with 2.0.7.

Does anyone know what's going on here? I'm not on the kernel mailing list,
please reply to me directly.

Thanks - Jim

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/file.h>

main()
{
int fd;

printf("Opening file\n");
if (fd=open("lockfile",O_RDWR) < 0) {
printf("Open failed\n");
exit(1);
}
printf("File opened, locking for write\n");
if (flock(fd,LOCK_EX)) {
printf("Lock failed\n");
exit(1);
}
printf("File locked for write, sleeping 15 seconds\n");
sleep(15);
if (flock(fd,LOCK_UN)) {
printf("Unlock failed\n");
exit(1);
}
printf("File unlocked from write, exiting\n");
close(fd);
exit(0);
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html