Bug 95191
Summary: | document behavior of open(2) when path names a fifo with no readers | ||
---|---|---|---|
Product: | Documentation | Reporter: | Jason Vas Dias (jason.vas.dias) |
Component: | man-pages | Assignee: | documentation_man-pages (documentation_man-pages) |
Status: | RESOLVED CODE_FIX | ||
Severity: | normal | CC: | mtk.manpages |
Priority: | P1 | ||
Hardware: | All | ||
OS: | Linux | ||
Kernel Version: | Subsystem: | ||
Regression: | No | Bisected commit-id: | |
Attachments: |
illustrates problem - #1 working version that uses open
illustration #2: program that attempts to enable SIGIO on output fd 1 only - fails to recieve SIGIO better version of t_sigio_write_no_open |
Description
Jason Vas Dias
2015-03-21 15:16:27 UTC
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 ? Created attachment 171551 [details]
illustrates problem - #1 working version that uses open
Created attachment 171561 [details]
illustration #2: program that attempts to enable SIGIO on output fd 1 only - fails to recieve SIGIO
Should have added: To test: Save attachment #1 [details] as t_sigio_writer.c Save attachment #2 [details] 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. Oops : $ ./t_sigio_writer_no_open </tmp/a.fifo & should have been: $ ./t_sigio_writer_no_open >/tmp/a.fifo & Oops! Actually, all tests pass if compiled with '-pthread' . Created attachment 171581 [details]
better version of t_sigio_write_no_open
Hello Jason, (In reply to Jason Vas Dias from comment #0) > 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 [...] > 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 (In reply to Jason Vas Dias from comment #1) > 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 Thanks for taking a look at this, Micheal. As you suggested, I opened another bug: Bug #95331 - please take a look. |