Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Aug 1997 03:00:01 -0700 (PDT)
From:      tetsuya@secom-sis.co.jp (Tetsuya Furukawa)
To:        freebsd-bugs
Subject:   Re: kern/4243: file locking doesn't work for pipe 
Message-ID:  <199708081000.DAA06716@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/4243; it has been noted by GNATS.

From: tetsuya@secom-sis.co.jp (Tetsuya Furukawa)
To: peter@spinner.dialix.com.au
Cc: dg@root.com, FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: kern/4243: file locking doesn't work for pipe 
Date: Fri, 8 Aug 1997 18:58:53 +0900

 Since I remembered the proper specification of flock(), I also think
 that flock() for a file descriptor shared among different processes
 is obviously useless.
 
 But fcntl() for a shared file descriptor may be useful because
 fcntl() has the other specification.
 In fact, the following program prints "fcntl works fine." on
 FreeBSD 2.2-STABLE i386.
 ----
 #include <sys/file.h>
 #include <sys/errno.h>
 #include <errno.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
 
 int
 main()
 {
     int fd;
     struct flock flbuf;
     char c;
     flbuf.l_start = 0;
     flbuf.l_len = 0;
     flbuf.l_type = F_WRLCK;
     flbuf.l_whence = SEEK_SET;
 
     fd = open("lockfile", O_WRONLY | O_CREAT, 0666);
     if (fork() == 0) {
 	/* child */
 	fcntl(fd, F_SETLKW, &flbuf);
 	sleep(2);
 	exit(0);
     }
 
     /* parent */
     sleep(1);
     if (fcntl(fd, F_SETLK, &flbuf) == -1) {
 	if (errno == EAGAIN)
 	    printf("fcntl works fine.\n");
 	else
 	    printf("fcntl fails: %s\n", strerror(errno));
     } else
 	printf("fcntl is discarded.\n");
     return 0;
 }
 ----
 
 File locking for a pipe by fcntl() fails on FreeBSD.
 I think the priority of supporting it is low.
 
 To the developer of the Apache's module, I suggested to do fcntl()
 for a temporary file. 
 
 --
 Tetsuya FURUKAWA  in Tokyo, Japan
 PGP Key fingerprint = C2 86 A6 7C 72 A0 A1 94  F4 4C 83 9D D1 E3 47 BD



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199708081000.DAA06716>