Page MenuHomeFreeBSD

mail: exit with the correct exit status on SIGHUP
ClosedPublic

Authored by kevans on May 8 2025, 1:49 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Jul 9, 3:58 AM
Unknown Object (File)
Wed, Jul 9, 12:33 AM
Unknown Object (File)
Tue, Jul 8, 1:37 PM
Unknown Object (File)
Mon, Jul 7, 9:53 AM
Unknown Object (File)
Sun, Jul 6, 4:58 PM
Unknown Object (File)
Fri, Jul 4, 10:21 PM
Unknown Object (File)
Fri, Jul 4, 8:40 AM
Unknown Object (File)
Thu, Jul 3, 3:27 PM
Subscribers

Details

Summary

Motivated by POSIX conformance requirements: mailx(1) is expected to
take the default action for every signal except SIGINT in interactive
mode. We still handle other signals that we shouldn't based on the
spec (e.g., SIGTSTP), but conforming there is not as straightforward as
we do more than just cleanup in response.

Note that when the spec says that we must take the default action, it
does not mean so strictly. Namely, we *can* do some sensible cleanup
if we'd like, but we enter into nonconformant territory if we don't
reflect the termination via signal in our exit status. That is why
this change doesn't actually remove the handler; we're still conformant
as long as the end result is the same as if we took the default action.

Diff Detail

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

Event Timeline

kevans requested review of this revision.May 8 2025, 1:49 AM
usr.bin/mail/collect.c
703

This isn't safe to do in a signal context, but I suppose addressing that is out of scope...

704

Also unsafe.

usr.bin/mail/collect.c
704

Yeah, I think as a whole mail(1) could use more work, but at the same time it's been doing this wrong since before I was born so I don't think I can justify us putting the time into it at the moment.

This revision is now accepted and ready to land.May 11 2025, 1:18 PM
des requested changes to this revision.May 11 2025, 1:37 PM
des added inline comments.
usr.bin/mail/collect.c
711

I expanded the tests and discovered that this line is in fact reached, because SIGHUP is blocked. You need to unblock it as in collstop() above.

This revision now requires changes to proceed.May 11 2025, 1:37 PM

Fix Dag-Erling's test in D50296

The root cause of the failure is that we would always fallback to _exit(2),
because the signal would not be re-delivered until after the handler has
returned.

One could unblock the signal as collstop() does, but the main benefit it has
there is that the signal will stop the process in the middle of the handler and
we can jump back into the normal collect() flow with the signal restored.

For collhup(), let's opt to avoid the complexity and just kick the _exit()
fallback. This does assume that we're not just temporarily unblocked because
collect() is is using, e.g., pselect()/ppoll(), but work to that end would
require a lot more of a re-think and we'll have tests for the new behavior.

This revision is now accepted and ready to land.May 14 2025, 10:11 AM