Date: Sat, 3 Aug 1996 19:37:16 -0700 (PDT) From: Archie Cobbs <archie@whistle.com> To: freebsd-hackers@freebsd.org Subject: flock() broken on certain files Message-ID: <199608040237.TAA05031@bubba.whistle.com>
next in thread | raw e-mail | index | archive | help
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 <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <err.h> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199608040237.TAA05031>