Re: locking race condition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Emmanuel Dreyfus <manu@xxxxxxxxxx> wrote:

> # echo "xxx"|cat -l > test9 
> cat: stdout: No such file or directory

I realize the -l flag for cat is a NetBSD extension. Here is a test case in C
that exhibit the problem. As shown in the transcript below, it does not fails
all the time, sometime I have to run it a few times to get the failure:

$ cat lockrace.c                                                               
/* cc -o lockrace lockrace.c */
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <err.h>
#include <sysexits.h>
#include <sys/param.h>

int
main(void)
{
        char filename[MAXPATHLEN + 1];
        int fd;
        struct flock fl;

        (void)snprintf(filename, MAXPATHLEN, "test-%d", getpid());
        if ((fd = open(filename, O_CREAT|O_EXCL|O_RDWR, 0644)) == -1)
                err(EX_OSERR, "open \"%s\" failed", filename);

        fl.l_len = 0;
        fl.l_start = 0;
        fl.l_type = F_WRLCK;
        fl.l_whence = SEEK_SET;

        if (fcntl(fd, F_SETLKW, &fl) == -1)
                err(EX_OSERR, "fcntl F_SETLKW on \"%s\" failed", filename);

        return EX_OK;
}
$ cc -o lockrace lockrace.c                                                    
$ ./lockrace                                                                   
$ ./lockrace 
$ ./lockrace 
$ ./lockrace 
$ ./lockrace 
lockrace: fcntl F_SETLKW on "test-19894" failed: No such file or directory

-- 
Emmanuel Dreyfus
http://hcpnet.free.fr/pubz
manu@xxxxxxxxxx



[Index of Archives]     [Gluster Users]     [Ceph Users]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux