Bug 19087

Summary: selects always restart when using threads
Product: Base System Reporter: bryanm <bryanm>
Component: miscAssignee: Daniel Eischen <deischen>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.0-RELEASE   
Hardware: Any   
OS: Any   

Description bryanm 2000-06-07 09:40:00 UTC
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.
Comment 1 Jason Evans freebsd_committer freebsd_triage 2000-06-07 20:36:07 UTC
Responsible Changed
From-To: freebsd-bugs->jasone

Over to maintainer. 
Comment 2 Daniel Eischen freebsd_committer freebsd_triage 2000-09-04 14:53:07 UTC
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. 


Comment 3 Daniel Eischen freebsd_committer freebsd_triage 2000-09-04 14:53:07 UTC
Responsible Changed
From-To: jasone->deischen

I've got changes to signal handling in the threads library in the 
works.
Comment 4 Daniel Eischen freebsd_committer freebsd_triage 2000-11-17 23:56:59 UTC
State Changed
From-To: analyzed->closed

This has been fixed in both -current and -stable.