[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gluster-devel] locking race condition
From: |
Emmanuel Dreyfus |
Subject: |
Re: [Gluster-devel] locking race condition |
Date: |
Mon, 20 Aug 2012 06:35:49 +0200 |
User-agent: |
MacSOUP/2.7 (unregistered for 2039 days) |
Emmanuel Dreyfus <address@hidden> 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
address@hidden