NSM: Detect death of clients whose processes are not children of NSMD.
This commit is contained in:
parent
d5ed4e8ada
commit
b9f297bb20
|
@ -225,16 +225,10 @@ void clear_clients ( void )
|
|||
}
|
||||
}
|
||||
|
||||
void handle_sigchld ( )
|
||||
{
|
||||
for ( ;; )
|
||||
{
|
||||
int status;
|
||||
pid_t pid = waitpid(-1, &status, WNOHANG);
|
||||
if (pid <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
void
|
||||
handle_client_process_death ( int pid )
|
||||
{
|
||||
Client *c = get_client_by_pid( (int)pid );
|
||||
|
||||
if ( c )
|
||||
|
@ -267,6 +261,20 @@ void handle_sigchld ( )
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void handle_sigchld ( )
|
||||
{
|
||||
for ( ;; )
|
||||
{
|
||||
int status;
|
||||
pid_t pid = waitpid(-1, &status, WNOHANG);
|
||||
|
||||
if (pid <= 0)
|
||||
break;
|
||||
|
||||
handle_client_process_death( pid );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -576,6 +584,39 @@ purge_inactive_clients ( )
|
|||
}
|
||||
}
|
||||
|
||||
bool
|
||||
process_is_running ( int pid )
|
||||
{
|
||||
if ( 0 == kill( pid, 0 ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if ( ESRCH == errno )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
purge_dead_clients ( )
|
||||
{
|
||||
std::list<Client*> tmp( client );
|
||||
|
||||
for ( std::list<Client*>::const_iterator i = tmp.begin();
|
||||
i != tmp.end();
|
||||
++i )
|
||||
{
|
||||
const Client *c = *i;
|
||||
if ( c->pid )
|
||||
{
|
||||
if ( ! process_is_running( c->pid ) )
|
||||
handle_client_process_death( c->pid );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/************************/
|
||||
/* OSC Message Handlers */
|
||||
/************************/
|
||||
|
@ -827,6 +868,8 @@ wait_for_killed_clients_to_die ( )
|
|||
handle_sigchld();
|
||||
}
|
||||
|
||||
purge_dead_clients();
|
||||
|
||||
usleep( 200 * 1000 );
|
||||
}
|
||||
|
||||
|
@ -1748,6 +1791,8 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
osc_server->wait( 1000 );
|
||||
|
||||
purge_dead_clients();
|
||||
}
|
||||
|
||||
// osc_server->run();
|
||||
|
|
Loading…
Reference in New Issue