On Thu, 22 Jul 2004 14:08:41 +0200 Matthias Andree <matthias.andree@gmx.de> wrote:
Tim Southerwood <ts@doc.ic.ac.uk> writes:
- fcntl with F_SETLKW will not work against a Solaris 2.8 server as proved with a small test program. Other forms of fcntl (ie F_SETLK) are OK.
Why not? Can you show the test program?
Don't know why yet - I assume it's unimplemented in the Solaris NFS dialect?
Here's the test program, fcntltest.c
//*********************************************************
#include <stdio.h> #include <unistd.h> #include <fcntl.h>
main(int argc, char* argv[]) { if (argc != 2) { fprintf (stderr, "Usage: %s filetolock\n", argv[0]); return(1); }
int result;
int fd;
struct flock lock;
char *filetolock;
int locked=0;
filetolock = argv[1];
fd = open(filetolock, O_RDWR);
if (fd == -1)
{
fprintf(stderr, filetolock);
perror (" - error opening file");
return(2);
}
lock.l_type = F_RDLCK; /* F_RDLCK, F_WRLCK, F_UNLCK */
lock.l_start = 0; /* byte offset relative to l_whence */
lock.l_whence = SEEK_SET; /* SEEK_SET, SEEK_CUR, SEEK_END */
lock.l_len = 0; /* #bytes (0 means to EOF) */
result = fcntl(fd, F_SETLKW, &lock);
if (result == -1)
{
perror("Error locking file with F_SETLKW");
}
else
{
printf("Locked with F_SETLKW\n");
locked=1;
}
if (!locked)
{
result = fcntl(fd, F_SETLK, &lock);
if (result == -1)
{
perror("Error locking file with F_SETLK");
}
else
{
printf ("Locked with F_SETLK\n");
locked=1;
}
}
if (locked)
{
printf("Sleeping - try to lock same file from second
process\n"); sleep(30); } close(fd); printf("File closed\n"); }
//*********************************************************
gcc -o fcntltest fcntltest.c
# The linux NFS server from linux client # ts@lenin > ./fcntltest /vol/csg/public/users/ts/wibble.blah Locked with F_SETLKW Sleeping - try to lock same file from second process File closed
# The local filesystem # ts@lenin > ./fcntltest /tmp/p.ps Locked with F_SETLKW Sleeping - try to lock same file from second process File closed
# The Solaris 2.8 server # ts@lenin > ./fcntltest /homes/ts/liquid-1.0.0.tar.gz Error locking file with F_SETLKW: No locks available Locked with F_SETLK Sleeping - try to lock same file from second process File closed
That seems to verify it in my setup.
Cheers
Tim
-- Tim J Southerwood Senior Programmer CSG, Dept of Computing, Imperial College, London
-- Mr Tim J Southerwood Senior Programmer CSG, Dept of Computing, Imperial College, London Email personal: ts@dionic.net work: ts@doc.ic.ac.uk Tel home: +44 (0)1892 824850 mobile: +44 (0)7739-902439 work: +44 (0)20-759-48392