| Summary: | selects always restart when using threads | ||
|---|---|---|---|
| Product: | Base System | Reporter: | bryanm <bryanm> |
| Component: | misc | Assignee: | Daniel Eischen <deischen> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | 4.0-RELEASE | ||
| Hardware: | Any | ||
| OS: | Any | ||
Responsible Changed From-To: freebsd-bugs->jasone Over to maintainer. State Changed From-To: open->analyzed Take over responsiblity for this; I've got some threads library changes in the pipe. signal(3) installs signal handlers using sigaction(2) and sets the sa_flags to SA_RESTART. Before sigaction(2), earlier BSDs automatically restarted some system calls when handlers were installed using signal(2). Now, the library routine signal(3) tries to keep this behaviour by using SA_RESTART, and the threads library obeys this flag. signal(3) should be deprecated in preference to the POSIX sigaction(). Use sigaction() to install the signal handler with sa_flags set to 0, and select() will be interrupted upon receipt of a signal. I want to close this PR, but will wait a bit for response from the submitter. Responsible Changed From-To: jasone->deischen I've got changes to signal handling in the threads library in the works. State Changed From-To: analyzed->closed This has been fixed in both -current and -stable. |
Threads blocking on select default to being restarted after signals. Shouldn't the default be to interrupt, given that these are POSIX threads? Calling siginterrupt(1) doesn't help, since it isn't thread aware. One has to use sigaction to explicity set sa_flags to 0 to get the POSIX behaviour. Fix: libc_r includes an implementation of signal which implements the POSIX semantics, but it is not listed in HIDDEN_SYSCALLS, so the libc implementation gets used anyway. Is this an oversight, or is this merely a porting issue? Are there any other side effects due to calling the libc signal? How-To-Repeat: In a threaded app (eg, slapd from openldap-1.2.10): int shutdown = 0; signal( SIGTERM, set_shutdown) while (!shutdown) { i = select( nfds, &readfds, &writefds, 0, 0) ... } void set_shutdown( int sig ) { shutdown = 1 } In response to a SIGTERM, shutdown is set to 1, but if the fds are idle, the process never exits because the select restarts each time.