From owner-freebsd-hackers Sat Aug 3 19:38:22 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id TAA05909 for hackers-outgoing; Sat, 3 Aug 1996 19:38:22 -0700 (PDT) Received: from whistle.com (s205m131.whistle.com [207.76.205.131]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id TAA05904 for ; Sat, 3 Aug 1996 19:38:19 -0700 (PDT) Received: (from smap@localhost) by whistle.com (8.7.5/8.6.12) id TAA11223; Sat, 3 Aug 1996 19:37:43 -0700 (PDT) Received: from bubba.whistle.com(207.76.205.7) by whistle.com via smap (V1.3) id sma011221; Sat Aug 3 19:37:17 1996 Received: (from archie@localhost) by bubba.whistle.com (8.6.12/8.6.12) id TAA05031; Sat, 3 Aug 1996 19:37:16 -0700 From: Archie Cobbs Message-Id: <199608040237.TAA05031@bubba.whistle.com> Subject: flock() broken on certain files To: freebsd-hackers@freebsd.org Date: Sat, 3 Aug 1996 19:37:16 -0700 (PDT) X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk How hard would it be to get flock() to work on a fifo? Right now it seems that it doesn't... could someone else verify this? It seems that fifo's are exactly the kind of thing you would want to be able to set a lock on, e.g., when multiple processes are writing to it. Here's a sample program: /* foo.c */ #include #include #include #include #include int main() { int fd; FILE *fp; fd = open("fifo", O_WRONLY, O_EXLOCK | O_NONBLOCK); if (fd < 0) { warn("pid %lu: open", getpid()); exit(1); } if ((fp = fdopen(fd, "a")) == NULL) { warn("pid %lu: fdopen", getpid()); exit(1); } warnx("pid %lu opened fifo", getpid()); sleep(5); fprintf(fp, "pid %lu reporting 1\n", getpid()); fflush(fp); sleep(5); fprintf(fp, "pid %lu reporting 2\n", getpid()); fflush(fp); sleep(5); fprintf(fp, "pid %lu reporting 3\n", getpid()); fflush(fp); warnx("pid %lu exiting", getpid()); return(0); } The open()'s are not being blocked, even though O_EXLOCK is specified: $$ mkfifo fifo csh: cat fifo > /dev/null & [3] 5017 $$ ./foo & [4] 5018 foo: pid 5018 opened fifo $$ ./foo & [5] 5019 foo: pid 5019 opened fifo $$ wait foo: pid 5018 exiting [4] Done ./foo foo: pid 5019 exiting [5] Done ./foo [3] Done cat fifo > /dev/null $$ -Archie ___________________________________________________________________________ Archie L. Cobbs, archie@whistle.com * Whistle Communications Corporation