Page MenuHomeFreeBSD

system(3): Improve signal handling
ClosedPublic

Authored by des on Mon, Feb 23, 9:35 PM.
Tags
None
Referenced Files
F146256268: D55471.id172546.diff
Sun, Mar 1, 4:14 AM
F146256245: D55471.id172548.diff
Sun, Mar 1, 4:14 AM
F146256238: D55471.id172616.diff
Sun, Mar 1, 4:14 AM
F146256219: D55471.id172582.diff
Sun, Mar 1, 4:14 AM
F146252870: D55471.id172586.diff
Sun, Mar 1, 3:33 AM
F146252834: D55471.id172708.diff
Sun, Mar 1, 3:32 AM
F146247478: D55471.id172620.diff
Sun, Mar 1, 2:26 AM
F146247464: D55471.id172696.diff
Sun, Mar 1, 2:26 AM
Subscribers

Details

Summary

Ignore SIGINT and SIGQUIT and block SIGCHLD, as POSIX requires.

To deal with the concurrency problem described in POSIX, we keep track
of the count of concurrent invocations. We ignore and block signals
only when the counter was zero before we incremented it, and restore
them only when the counter reaches zero after we decrement it.

Note that this does not address the issue of thread cancellation.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 70951
Build 67834: arc lint + arc unit

Event Timeline

des requested review of this revision.Mon, Feb 23, 9:35 PM

This seems fine to me, although I had to do math using my fingers for the counting.

des retitled this revision from system: Improve signal handling to system(3): Improve signal handling.Tue, Feb 24, 1:43 PM
des edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Tue, Feb 24, 2:07 PM
This revision now requires review to proceed.Tue, Feb 24, 5:33 PM
kevans added inline comments.
lib/libc/stdlib/system.c
125

I don't think we necessarily want to apply this large of a hammer.

In particular, I don't think we want to clobber any parts of the mask that aren't SIGCHLD on those systems that actually try to propagate updates to other threads with sigprocmask(). On FreeBSD, we're potentially restoring a completely unrelated thread's signal mask to the current thread.

Actually, after writing out that last bit, that does mean that FreeBSD should be doing the mask manipulation on every call instead of just on the first/last.

fix SIGCHLD issues raised in review

des marked an inline comment as done.Tue, Feb 24, 6:44 PM
des added inline comments.
lib/libc/stdlib/system.c
59

@dim in your opinion, should concurrent here be volatile, or is the fact that it's static sufficient to deter optimization?

lib/libc/stdlib/system.c
59

I think static or not doesn't matter for whether the compiler will decide to reload the variable even though it (from its perspective) could not have changed. If other threads are updating the same variable concurrently, you should ideally use atomic operations, but volatile will also work in this case.

lib/libc/stdlib/system.c
59

It was atomic in a previous version of the patch, but the spinlock (which is needed for other reasons) makes that unnecessary, I think. I'll add volatile.

This revision is now accepted and ready to land.Wed, Feb 25, 8:22 PM
This revision was automatically updated to reflect the committed changes.