Skip to contentSkip to conversation

New: document behavior of open(2) when path names a fifo with no readers

Bug 95191 bugzilla-daemon-590EEB7GvNiWaY/[email protected] 1 participant 11 messages Mar 21, 2015 – Mar 23, 2015 1 message not in the archive Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

https://bugzilla.kernel.org/show_bug.cgi?id=95191

Bug ID: 95191
Summary: document behavior of open(2) when path names a fifo
with no readers
Product: Documentation
Version: unspecified
Hardware: All
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: man-pages
Assignee: documentation_man-pages-ztI5WcYan/[email protected]
Reporter: [email protected]
Regression: No

linux 3.13 open() , if the path refers to a fifo, and O_WRONLY is set in its flags , but not O_NONBLOCK, then it does not return until a reader has connected to the output end of the pipe.

This fact is not documented anywhere in the open(2) manual page - in fact, it only mentions :

ENXIO O_NONBLOCK | O_WRONLY is set, the named file is a FIFO and no
process
has the file open for reading. Or, the file is a device special
file
and no corresponding device exists.

You can easily verify this behaviour with bash :

  $ mkfifo /tmp/a.fifo
  $ strace -f bash -c 'echo 1 >/tmp/a.fifo' &
  ...
  open("/tmp/a.fifo", O_WRONLY|O_CREAT|O_TRUNC, 0666
  $ read res </tmp/a.fifo
) = 3
fcntl(1, F_GETFD)                       = 0
fcntl(1, F_DUPFD, 10)                   = 10
fcntl(1, F_GETFD)                       = 0
fcntl(10, F_SETFD, FD_CLOEXEC)          = 0
dup2(3, 1)                              = 1
close(3)                                = 0
write(1, "1\n", 2)                      = 2
dup2(10, 1)                             = 1
fcntl(10, F_GETFD)                      = 0x1 (flags FD_CLOEXEC)
close(10)                               = 0
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
exit_group(0)                           = ?
+++ exited with 0 +++

Please add words to the effect :

"If the path refers to a named pipe (FIFO), and O_NONBLOCK is not set,
open() will block until a reader is connected to the write end of the pipe.
"
to the open(2) manual page.

Signature · 6 lines
You are receiving this mail because:
You are watching the assignee of the bug.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

[Bug 95191] document behavior of open(2) when path names a fifo with no readers

In reply to a message not in the archive

https://bugzilla.kernel.org/show_bug.cgi?id=95191

--- Comment #1 from Jason Vas Dias <[email protected]> --- I think the fcntl documentation is also particularly misleading when it
suggests
that output file descriptors can be enabled to have SIGIO sent for them when only O_ASYNC and not O_NONBLOCK bits are set in the FD flags .
I cannot get the attached program to work if I do not open() the fifo file -
it will not do to simply fcntl(fd,F_SETFL,previous_flags|O_ASYNC) and fcntl(fd,F_SETOWN_EX,{ .type = F_OWNER_TID, .pid = gettid() }) and
sigio_sa = (struct sigaction)
{ .sa_sigaction = sigio_handler,
.sa_flags = SA_NODEFER | SA_SIGINFO
};
if( sigaction(SIGIO, &sigio_sa, &sigio_prev_sa)
and then expect the process / thread to receive SIGIO
where si->si_fd == 1 for stdout - the process never gets a SIGIO signal.
Is this a kernel bug ? if not why is this not documented ?

Signature · 6 lines
You are receiving this mail because:
You are watching the assignee of the bug.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw

[Bug 95191] document behavior of open(2) when path names a fifo with no readers

In reply to a message not in the archive

https://bugzilla.kernel.org/show_bug.cgi?id=95191

--- Comment #2 from Jason Vas Dias <[email protected]> --- Created attachment 171551
--> https://bugzilla.kernel.org/attachment.cgi?id=171551&action=edit
illustrates problem - #1 working version that uses open

Signature · 6 lines
You are receiving this mail because:
You are watching the assignee of the bug.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

[Bug 95191] document behavior of open(2) when path names a fifo with no readers

In reply to a message not in the archive

https://bugzilla.kernel.org/show_bug.cgi?id=95191

--- Comment #3 from Jason Vas Dias <[email protected]> --- Created attachment 171561
--> https://bugzilla.kernel.org/attachment.cgi?id=171561&action=edit
illustration #2: program that attempts to enable SIGIO on output fd 1 only - fails to recieve SIGIO

Signature · 6 lines
You are receiving this mail because:
You are watching the assignee of the bug.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw

[Bug 95191] document behavior of open(2) when path names a fifo with no readers

In reply to a message not in the archive

https://bugzilla.kernel.org/show_bug.cgi?id=95191

--- Comment #4 from Jason Vas Dias <[email protected]> --- Should have added:
To test:
Save attachment #1 as t_sigio_writer.c
Save attachment #2 as t_sigio_writer_no_open.c

  $ gcc -o t_sigio_writer t_sigio_writer.c
  $ mkfifo /tmp/a.fifo
  $ ./t_sigio_writer /tmp/a.fifo &
  $ read -d $'\004' res < /tmp/a.fifo && echo "RES: $res"
  RES:
  $
  $ gcc -o t_sigio_writer_no_open t_sigio_writer_no_open.c
  $ ./t_sigio_writer_no_open </tmp/a.fifo &
  $ read -d $'\004' res < /tmp/a.fifo && echo "RES: $res"
  ^C

An strace of 2nd process, which only does fcntl(1,F_SETFL,flags|O_ASYNC), and does identical signal handling, that had to be killed, shows it only gets a SIGIO on FD 0, not on FD 1, after <CTRL+C> is pressed.

Signature · 6 lines
You are receiving this mail because:
You are watching the assignee of the bug.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw

[Bug 95191] document behavior of open(2) when path names a fifo with no readers

In reply to a message not in the archive

https://bugzilla.kernel.org/show_bug.cgi?id=95191

--- Comment #5 from Jason Vas Dias <[email protected]> --- Oops :

$ ./t_sigio_writer_no_open </tmp/a.fifo &
should have been:
$ ./t_sigio_writer_no_open >/tmp/a.fifo &
Signature · 6 lines
You are receiving this mail because:
You are watching the assignee of the bug.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw

[Bug 95191] document behavior of open(2) when path names a fifo with no readers

In reply to a message not in the archive

https://bugzilla.kernel.org/show_bug.cgi?id=95191

--- Comment #6 from Jason Vas Dias <[email protected]> --- Oops! Actually, all tests pass if compiled with '-pthread' .

Signature · 6 lines
You are receiving this mail because:
You are watching the assignee of the bug.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#8 lore raw

[Bug 95191] document behavior of open(2) when path names a fifo with no readers

In reply to a message not in the archive

https://bugzilla.kernel.org/show_bug.cgi?id=95191

--- Comment #7 from Jason Vas Dias <[email protected]> --- Created attachment 171581
--> https://bugzilla.kernel.org/attachment.cgi?id=171581&action=edit
better version of t_sigio_write_no_open

Signature · 6 lines
You are receiving this mail because:
You are watching the assignee of the bug.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#9 lore raw

[Bug 95191] document behavior of open(2) when path names a fifo with no readers

In reply to a message not in the archive

https://bugzilla.kernel.org/show_bug.cgi?id=95191

Michael Kerrisk <[email protected]> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |[email protected]

--- Comment #8 from Michael Kerrisk <[email protected]> --- Hello Jason,

(In reply to Jason Vas Dias from comment #0)

Quoted 5 lines

linux 3.13 open() , if the path refers to a fifo, and O_WRONLY is set in its flags , but not O_NONBLOCK, then it does not return until a reader has connected to the output end of the pipe.

This fact is not documented anywhere in the open(2) manual page

[...]

Quoted 7 lines

Please add words to the effect :

"If the path refers to a named pipe (FIFO), and O_NONBLOCK is not set,
open() will block until a reader is connected to the write end of the
pipe.
"
to the open(2) manual page.

Well, there is already this text in the man page:

O_NONBLOCK or O_NDELAY
.... For the handling of FIFOs (named pipes), see also fifo(7).

(Were you aware of the fifo(7) page?)

But it's true that something could be said more prominently in open(2), I think. I added the following under NOTES:

FIFOs
Opening the read or write end of a FIFO blocks until the other end is also opened (by another process or thread). See fifo(7) for further details.

Thanks,

Michael

Signature · 6 lines
You are receiving this mail because:
You are watching the assignee of the bug.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#10 lore raw

[Bug 95191] document behavior of open(2) when path names a fifo with no readers

In reply to a message not in the archive

https://bugzilla.kernel.org/show_bug.cgi?id=95191

Michael Kerrisk <[email protected]> changed:

What |Removed |Added
----------------------------------------------------------------------------

             Status|NEW                         |RESOLVED
         Resolution|---                         |CODE_FIX

--- Comment #9 from Michael Kerrisk <[email protected]> --- (In reply to Jason Vas Dias from comment #1)

Quoted 4 lines

I think the fcntl documentation is also particularly misleading when it suggests
that output file descriptors can be enabled to have SIGIO sent for them when only O_ASYNC and not O_NONBLOCK bits are set in the FD flags .

Hello Jason,

I don't understand what you mean here. But, also, I would really prefer a separate bug report, since this seems to be a separate issue.

I'm going to close this bug. Could you raise the above as a separate topics, and repost example programs. But please: make the example programs as simple as possible. I see extraneous stuff in the code you posted already, which just makes it harder for me to work out what's going on.

Thanks,

Michael

Signature · 6 lines
You are receiving this mail because:
You are watching the assignee of the bug.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#11 lore raw

[Bug 95191] document behavior of open(2) when path names a fifo with no readers

In reply to a message not in the archive

https://bugzilla.kernel.org/show_bug.cgi?id=95191

--- Comment #10 from Jason Vas Dias <[email protected]> --- Thanks for taking a look at this, Micheal. As you suggested, I opened
another bug: Bug #95331 - please take a look.

Signature · 6 lines
You are receiving this mail because:
You are watching the assignee of the bug.
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html