linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Clayton <andrew@digital-domain.net>
To: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
Cc: linux-man@vger.kernel.org
Subject: Re: [PATCH 1/1] signalfd.2: Note about interactions with epoll & fork
Date: Mon, 23 Sep 2019 22:24:13 +0100	[thread overview]
Message-ID: <20190923222413.5c79b179@kappa.digital-domain.net> (raw)
In-Reply-To: <99e8bcda-c6f2-18bb-d28d-56d65693f233@gmail.com>

On Mon, 23 Sep 2019 16:49:29 +0200
"Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> wrote:

> Hello Andrew,

Hi Michael,

Thanks for the extensive reply!

[...]
 
> Thanks for all of the detail in the commit message! That's funky! But I
> suppose in the end it's not completely surprising, because of the fact
> that epoll is really notifying events on the open file description,
> and there may be multiple file descriptors that refer to that description
> (as for example, after fork()). It is however, still surprising to users 
> that you can read() from the FD, even though epoll doesn't say it's ready.

Ah, I gotta remember there's a distinction between descriptors &
descriptions ;) 

[...]

> Thanks for the proposed text. But I prefer to avoid mentioning 
> daemon(3), which has a longstanding bug described in its manual
> page). Also, I think we need to bring out the fact that the
> signalfd still makes signals available for reading, even though

Yes, true.

> epoll does not say the FD is ready. Also, your text might
> lead the reader to think that this sequence might be possible:
> 
> create signalfd
> create epoll instance
> add signalfd to epoll instance
> fork()
>        In child: add signalfd to epoll instance
> 
> That last step will of course give an EEXIST error from
> epoll_ctl(), because  that FD is already in the epoll
> instance.

Yup.
 
> So, I've applied your patch, but then done a fairly major rewrite,
> so that the text now looks like:
> 
>    epoll(7) semantics
>        If a process adds (via epoll_ctl(2)) a signalfd file descriptor to
>        an epoll(7) instance, then epoll_wait(2) returns events  only  for
>        signals  sent to that process.  In particular, if the process then
>        uses fork() to create a child process, then the child will be able
>        to  read(2)  signals  that  are sent to it using the signalfd file
>        descriptor, but epoll_wait(2) will not indicate that the  signalfd
>        file descriptor is ready.  In this scenario, a possible workaround
>        is that after the fork(2), the child process can  close  the  sig‐
>        nalfd  file  descriptor  that it inherited from the parent process
>        and then create another signalfd file descriptor and add it to the
>        epoll  instance.   Alternatively,  the  parent and the child could
>        delay creating their  (separate)  signalfd  file  descriptors  and
>        adding them to the epoll instance until after the call to fork(2).
> 
> Seem okay to you?

Yes, looks good.
 
> I also verified this weirness using the program shown below:

Nice example.

[...]

Cheers,
Andrew

      reply	other threads:[~2019-09-23 21:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-20 23:42 [PATCH 0/1] Point out the interactions of signalfd with epoll & fork Andrew Clayton
2019-09-20 23:42 ` [PATCH 1/1] signalfd.2: Note about interactions " Andrew Clayton
2019-09-23 14:49   ` Michael Kerrisk (man-pages)
2019-09-23 21:24     ` Andrew Clayton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190923222413.5c79b179@kappa.digital-domain.net \
    --to=andrew@digital-domain.net \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).