You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apache-bugdb@apache.org by Marc Slemko <ma...@znep.com> on 1997/09/08 06:00:02 UTC

Re: general/1056: USE_FLOCK_SERIALIZED_ACCEPT is no use. (fwd)

The following reply was made to PR general/1056; it has been noted by GNATS.

From: Marc Slemko <ma...@znep.com>
To: Apache bugs database <ap...@apache.org>
Subject: Re: general/1056: USE_FLOCK_SERIALIZED_ACCEPT is no use. (fwd)
Date: Sun, 7 Sep 1997 21:51:41 -0600 (MDT)

 
 
 
 ---------- Forwarded message ----------
 Date: Mon, 8 Sep 1997 12:03:45 +0900
 From: Tetsuya Furukawa <te...@secom-sis.co.jp>
 To: marc@hyperreal.org, apache-bugdb@apache.org, marc@apache.org
 Subject: Re: general/1056: USE_FLOCK_SERIALIZED_ACCEPT is no use.
 
 Marc Slemko wrote:
 >State-Changed-Why:
 >I am unable to duplicate this problem on FreeBSD.  Are
 >you mounting things via NFS?
 
 No, I didn't use NFS.
 I don't know why you couldn't duplicate it.
 
 The problem is neither caused by NFS, nor FreeBSD.
 The Apache's programmers seem to suppose that flock() is compatible
 with fcntl().
 However, the supposition is wrong.
 
 The following program will tell you the proper usage of flock().
 --------
 #include <sys/file.h>
 #include <sys/errno.h>
 #include <errno.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
 
 int
 main(int argc, char **argv)
 {
     int fd;
     int bad = argc >= 2 && strcmp(argv[1], "bad") == 0;
 
     if (bad)
 	fd = open("lockfile", O_WRONLY | O_CREAT, 0666);
     if (fork() == 0) {
 	/* child */
 	if (!bad)
 	    fd = open("lockfile", O_WRONLY | O_CREAT, 0666);
 	flock(fd, LOCK_EX);
 	sleep(2);
 	exit(0);
     }
 
     /* parent */
     sleep(1);
     if (!bad)
 	fd = open("lockfile", O_WRONLY);
     if (flock(fd, LOCK_EX | LOCK_NB) == -1) {
 	if (errno == EWOULDBLOCK)
 	    printf("flock works fine.\n");
 	else
 	    printf("flock fails: %s\n", strerror(errno));
     } else
 	printf("flock doesn't work.\n");
     return 0;
 }
 --------
 
 The platforms, the command lines and the corresponding outputs are below.
 
 FreeBSD | ./a.out     | locking works file.
 FreeBSD | ./a.out bad | locking doesn't work.
 Solaris | ./a.out     | locking works file.
 Solaris | ./a.out bad | locking works file.
 
 Note: Solaris's flock() seems to be using fcntl() internally,
       so it often has the funny behavior.
 
 --
 Tetsuya FURUKAWA, Tokyo, Japan.