On Sat, Nov 06, 1999 at 12:50:16AM +0100, Ollivier Robert wrote:

A child process seems to be able to let go of a parent's lock on
4.0 by closing a file discriptor, the same doesn't seem to be true
on 3.3.

For example, if you try to run two copies of the included program
as on 3.3, you get a resource unavailable message.

        12:57:walton 6% ./lockf_test /tmp/blah 5 &
        [1] 2453
        13:01:walton 7% ./lockf_test /tmp/blah 5
        Unable to open file: Resource temporarily unavailable
        13:01:walton 8%
        [1]    Done                          ./lockf_test /tmp/blah 5

On 4.0 two run concurrently quite happily:

        12:54:gonzo 65% ./lockf_test /tmp/blah 5 &
        [1] 943
        13:02:gonzo 66% ./lockf_test /tmp/blah 5
        [1]    Done                          ./lockf_test /tmp/blah 5
        13:02:gonzo 67%

If you remove the "if(fork==0){close(fd);}" it two copies will not
run concurrently on 4.0. I'm not sure which behavior is correct, but
I suspect the 3.0 behavior is, 'cos /usr/bin/lockf is broken by
this on 4.0.

        David.

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc,char **argv)
{
        int fd;

        if( argc != 3 ) {
                fprintf(stderr, "Usage: %s filename seconds\n", argv[0]);
                exit(1);
        }

        if( (fd = open(argv[1], O_RDONLY|O_CREAT|O_NONBLOCK|O_EXLOCK,0666)) == -1 ) {
                perror("Unable to open file");
                exit(2);
        }

        if( fork() == 0 ) {
                close(fd);
        }

        sleep(atoi(argv[2]));

        exit(0);
}


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to