STC for libapr fcntl failure
David Rothenberger
daveroth@acm.org
Fri Apr 26 15:59:00 GMT 2013
The libapr1 tests are failing for Cygwin 64-bit when trying to use
fcntl(3) for process mutexes. Calling fcntl() to acquire the lock
currently fails with a "lock: Bad address" error.
I've attached a simple test case that demonstrates the problem. Just
run "make" to build and run it.
--
David Rothenberger ---- daveroth@acm.org
Encyclopedia Salesmen:
Invite them all in. Nip out the back door. Phone the police
and tell them your house is being burgled.
-- Mike Harding, "The Armchair Anarchist's Almanac"
-------------- next part --------------
CC=gcc
CFLAGS=-Wall
STC=stc-fcntl
.PHONY: test
test: $(STC)
./$(STC)
$(STC): $(STC).c
$(CC) $(CFLAGS) -o $@ $^
.PHONY: clean
clean:
rm -f $(STC)
-rm -f /tmp/fcntl*
-------------- next part --------------
/***********************************************************************
* This is a STC to show that fcntl fails.
*
* It tries to use fcntl() for file locking. It creates a temporary
* file and tries to lock and then unlock the file.
*
* This produces "lock: Bad address" with Cygwin 1.7.19 x86_64.
*
* Compile: gcc -Wall -o stc-fcntl stc-fcntl.c
***********************************************************************/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/wait.h>
#include <sys/file.h>
/* A temporary file used for fcntl. */
char tmpfilename[] = "/tmp/fcntlXXXXXX";
struct flock mutex_lock_it;
struct flock mutex_unlock_it;
int main(int argc, const char * const * argv, const char * const *env)
{
int fd;
int rc;
/* Create the temporary file. */
fd = mkstemp(tmpfilename);
if (fd < 0) {
perror("open failed");
exit(1);
}
/* Setup mutexes */
mutex_lock_it.l_whence = SEEK_SET; /* from current point */
mutex_lock_it.l_start = 0; /* -"- */
mutex_lock_it.l_len = 0; /* until end of file */
mutex_lock_it.l_type = F_WRLCK; /* set exclusive/write lock */
mutex_lock_it.l_pid = 0; /* pid not actually interesting */
mutex_unlock_it.l_whence = SEEK_SET; /* from current point */
mutex_unlock_it.l_start = 0; /* -"- */
mutex_unlock_it.l_len = 0; /* until end of file */
mutex_unlock_it.l_type = F_UNLCK; /* set exclusive/write lock */
mutex_unlock_it.l_pid = 0; /* pid not actually interesting */
/* Get the lock. */
do {
rc = fcntl(fd, F_SETLKW, &mutex_lock_it);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
perror("lock");
exit(1);
}
/* Release the lock. */
do {
rc = fcntl(fd, F_SETLKW, &mutex_unlock_it);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
perror("unlock");
exit(1);
}
/* Clean up. */
close(fd);
unlink(tmpfilename);
return 0;
}
More information about the Cygwin-apps
mailing list