Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 2 Jun 2007 23:57:19 +0100
From:      "mal content" <artifact.one@googlemail.com>
To:        freebsd-hackers@freebsd.org
Subject:   Open FIFO non-blocking but have write() block(?)
Message-ID:  <8e96a0b90706021557h2168337emb9b7b59a2084530e@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hello.

The wording of the question in the subject is terrible,
I know. What I'm trying to do is write a program that
creates two named pipes in the filesystem. Logging
date appears on one, to be read by any external program
and commands are read by the program from the other.

If data is written to the logging FIFO and there's no
external reader, the log info is discarded.

The problem I'm having is that I can create the 'log'
fifo with mkfifo but the open call fails because there's
no reader:

  if (mkfifo("control", 0600) == -1) die();
  fd1 = open("control", O_RDONLY | O_NONBLOCK);
  if (fd1 == -1) die();

  if (mkfifo("log", 0600) == -1) die();
  fd2 = open("log", O_WRONLY | O_NONBLOCK);
  if (fd2 == -1) die();

Obviously I can remove the O_NONBLOCK from the second
open call, but this causes it to block and I don't want
that.

The behaviour I'm actually looking for is that the first
open() call should succeed but the first write made to
the fifo (with no reader) should fail.

Is it possible to portably get this behaviour from FIFOs?
Or should I be looking at something else like unix domain
sockets?

thanks,
MC



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