unlock fails if file not locked
Neal Norwitz
nnorwitz@gmail.com
Thu Aug 10 07:45:00 GMT 2006
This test was taken from the python test suite. It works on many
different platforms and architecture's except cygwin's. I'm not
entirely sure that cygwin is really wrong either though.
The attached c program should print only a single message:
lock failed in parent (expected) 13
However it also prints:
unlock failed in parent (not expected) 13
-bash-3.1$ uname -a
CYGWIN_NT-5.1 stella 1.7.0s(0.159/4/2) 20060802 23:48:39 i686 Cygwin
Also happens with 1.5.19 and 20 I'm pretty sure.
Please copy me on any follow up.
n
-------------- next part --------------
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
static void lock(int fd, const char *where, const char *expected)
{
struct flock lf = { .l_type = F_WRLCK, 0 };
int err = fcntl(fd, F_SETLK, &lf);
if (err < 0)
fprintf(stderr, "lock failed in %s (%sexpected) %d\n", where, expected, errno);
}
static void unlock(int fd, const char *where, const char *expected)
{
struct flock lf = { .l_type = F_UNLCK, 0 };
int err = fcntl(fd, F_SETLKW, &lf);
if (err < 0)
fprintf(stderr, "unlock failed in %s (%sexpected) %d\n", where, expected, errno);
}
int main(int argc, char**argv)
{
// int fd = open("foo", O_WRONLY | O_CREAT);
int fd = fileno(fopen("foo", "w"));
int err, pid = fork();
if (pid < 0) {
fprintf(stderr, "fork error\n");
return -1;
}
// in child
if (pid == 0) {
lock(fd, "child", "not ");
sleep(2);
unlock(fd, "child", "not ");
_exit(0);
}
sleep(1);
lock(fd, "parent", "");
// file isn't locked in child, but there should not be an error on cygwin
unlock(fd, "parent", "not ");
sleep(2);
return 0;
}
-------------- next part --------------
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
More information about the Cygwin
mailing list