Thread (44 messages) flat view 44 messages, 4 authors, 2024-02-01

Re: [RFC PATCH] pidfd: implement PIDFD_THREAD flag for pidfd_open()

From: Andy Lutomirski <luto@amacapital.net>
Date: 2024-01-31 19:25:00
Also in: lkml

On 01/31, Oleg Nesterov wrote:
quoted
On 01/31, Andy Lutomirski wrote:
Please note

      /* TODO: respect PIDFD_THREAD */

this patch adds into pidfd_send_signal().

See also this part of discussion

      > > +   /* TODO: respect PIDFD_THREAD */
      >
      > So I've been thinking about this at the end of last week. Do we need to
      > give userspace a way to send a thread-group wide signal even when a
      > PIDFD_THREAD pidfd is passed? Or should we just not worry about this
      > right now and wait until someone needs this?

      I don't know. I am fine either way, but I think this needs a separate
      patch and another discussion in any case. Anyway should be trivial,
      pidfd_send_signal() has the "flags" argument.

with Christian in https://lore.kernel.org/all/20240130112126.GA26108@redhat.com/ (local)
I missed that.  Whoops.

On Wed, Jan 31, 2024 at 11:15 AM Oleg Nesterov [off-list ref] wrote:
Forgot to mention...

And I agree that pidfd_send_signal(flags => PGID/SID) can make
some sense too.

But this a) doesn't depend on PIDFD_THREAD, and b) needs another
patch/discussion.

But again, I am not sure I understood you correctly.
Hmm.

When one works with regular (non-fd) pids / pgids etc, one specifies
the signal domain at the time that one sends the signal.  I don't know
what pidfds should do.  It seems a bit inefficient for anything that
wants a pidfd and might send a signal in a different mode in the
future to have to hold on to multiple pidfds, so it probably should be
a pidfd_send_signal flag.

Which leaves the question of what the default should be.  Should
pidfd_send_signal with flags = 0 on a PIDFD_THREAD signal the process
or the thread?  I guess there are two reasonable solutions:

1. flags = 0 always means process.  And maybe there's a special flag
to send a signal that matches the pidfd type, or maybe not.

2. flags = 0 does what the pidfd seems to imply, and a new
PIDFD_SIGNAL_PID flag overrides it to signal the whole PID even if the
pidfd is PIDFD_THREAD.

Do any of you have actual use cases in mind where one choice is
clearly better than the other choice?

--Andy
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help