/*********************************************************************** * This is a STC that causes the following error on my test machine: * NtCreateEvent(lock): 0xC0000035 * * It tries to use fcntl() for file locking. It creates a temporary * file, the uses fork to spawn a number of children. Each child opens * the file, then repeatedly uses fcntl to lock and unlock it. * * This test was extracted from the APR test suite. * * Compile: gcc -Wall -o stc-fcntl-fork stc-fcntl-fork.c ***********************************************************************/ #include #include #include #include #include #include #define MAX_ITER 2000 #define CHILDREN 6 /* A temporary file used for fcntl. */ char tmpfilename[] = "/tmp/fcntlXXXXXX"; struct flock mutex_lock_it; struct flock mutex_unlock_it; /* Fork and use fcntl to lock and unlock the file repeatedly in the child. */ void make_child(int trylock, pid_t *pid) { if ((*pid = fork()) < 0) { perror("fork failed"); exit(1); } else if (*pid == 0) { int fd2 = open(tmpfilename, O_RDWR); if (fd2 < 0) { perror("child open"); exit(1); } int rc; int i; for (i=0; i