Page MenuHomeFreeBSD

Make mqueeue objects work across a fork again.
ClosedPublic

Authored by imp on Jan 5 2020, 6:44 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Apr 20, 4:45 PM
Unknown Object (File)
Fri, Mar 29, 9:08 AM
Unknown Object (File)
Jan 17 2024, 5:52 PM
Unknown Object (File)
Jan 15 2024, 3:40 AM
Unknown Object (File)
Dec 22 2023, 9:20 PM
Unknown Object (File)
Nov 23 2023, 11:09 AM
Unknown Object (File)
Nov 15 2023, 1:39 AM
Unknown Object (File)
Oct 19 2023, 5:18 AM
Subscribers

Details

Summary

In r110908 (2003) alfred added DFLAG_PASSABLE to tag those types of FD
that can be passed via unix pipes, but mqeueuefs didn't exist
yet. Later, in r152825 (2005) davidxu neglected to include
DFLAG_PASSABLE sincee people don't normally pass thesee things via
unix sockets (it's a FreeBSD implementation detail that it's a file
descriptor, so why would they nootice). Then r223866 (2011) by
jonathan used the new flag in fdcopy, which fork uses which is where
mqueuefs actually broke mqueue objects being propagated by fork. Fix
this by tagging mqueuefs as passable as well. POSIX requires this to be the case as well.

PR: 243103

Test Plan

The test case in the bugzilla fails before this change and works after. Based on the history here, I'm sure this was an innocent oversight on David Xu's part which became noticeable after r223866 (jonathan didn't intend for this to be fallout based on the commit messagee) and it is correct (or r223866 is bogus for reusing this flag)

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 28489
Build 26548: arc lint + arc unit

Event Timeline

imp added reviewers: kib, mjg.
imp edited the test plan for this revision. (Show Details)

I am not sure if mq_notify() stuff would interact with fork and now pass for SIGEV_THREAD would handle this.

This revision is now accepted and ready to land.Jan 5 2020, 7:26 AM
jilles added a subscriber: jilles.

The mq_notify() mechanism indeed needs to be considered here, but I think it already handles that:

  • the kern_kmq_notify() code knows to tie a registration to a particular process and file descriptor number;
  • if a process closes an mq file descriptor, the registration (if any) it made to that descriptor number is removed;
  • if a process exits, all registrations it made are removed.

When using rfork() to share the file descriptor table between two processes, it appears to be possible (from code inspection, untested) that one process registers a notification, the second process closes the descriptor and the notification stays. This need not block this review.

This revision was automatically updated to reflect the committed changes.