Page MenuHomeFreeBSD

fd: add close_range(..., CLOSE_RANGE_CLOEXEC)
ClosedPublic

Authored by mjg on Mar 3 2022, 1:50 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Mar 22, 3:12 PM
Unknown Object (File)
Fri, Mar 22, 3:12 PM
Unknown Object (File)
Fri, Mar 22, 3:11 PM
Unknown Object (File)
Fri, Mar 22, 3:00 PM
Unknown Object (File)
Fri, Mar 22, 3:00 PM
Unknown Object (File)
Fri, Mar 22, 3:00 PM
Unknown Object (File)
Fri, Mar 22, 9:59 AM
Unknown Object (File)
Mar 8 2024, 6:32 AM
Subscribers

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

mjg requested review of this revision.Mar 3 2022, 1:50 PM

I would like to get this in for 13.1

Linux compat will be updated separately. For some reason it has DUMMY(close_range);

  • use the same value for the flag as linux to avoid future mess

Seems ok. It would be nice to have a simple regression test in tests/sys/file/closefrom_test.c to ensure this code gets exercised.

lib/libc/sys/closefrom.2
63
sys/kern/kern_descrip.c
1410

This error path leaks the lock.

1493–1494

This comment can be deleted.

sys/sys/unistd.h
206

Hmm but then you have to update the pattern used in libsysdecode. Alternately just write 0x4 since that's a more common style for flag definitions.

mjg added inline comments.
sys/sys/unistd.h
206

The above is copy-pasted from rfork. I had manually typed this off but it failed to patter-match, I don't think touching this is worth any effort.

mjg marked 3 inline comments as done.Mar 3 2022, 2:39 PM

How do you suggest to sensibly test this though? To my surprise I found procstat does not report CLOEXEC, so as is I would have to actually exec.

This revision is now accepted and ready to land.Mar 3 2022, 2:41 PM
In D34424#779939, @mjg wrote:

How do you suggest to sensibly test this though? To my surprise I found procstat does not report CLOEXEC, so as is I would have to actually exec.

You can use fcntl(F_GETFD) to test for the flag.

  • add a rudimentary unit test
This revision now requires review to proceed.Mar 3 2022, 3:13 PM

Thanks for adding the test.

tests/sys/file/closefrom_test.c
333

I'd check for an error from close_range(), though I see that the pre-existing tests do not for some reason.

343

This test will pass if fcntl() fails. It'd be more rigourous to check for failure before testing FD_CLOEXEC.

This revision is now accepted and ready to land.Mar 3 2022, 5:11 PM
This revision was automatically updated to reflect the committed changes.