mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
Make self-restarting: fork child and wait (to deal with asserts).
This commit is contained in:
parent
ddecfad8d1
commit
02833e4c17
1 changed files with 31 additions and 0 deletions
|
@ -47,6 +47,7 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__)
|
||||||
# if (OSVERSION > 500000)
|
# if (OSVERSION > 500000)
|
||||||
|
@ -451,6 +452,20 @@ SIGINT_handler( int sig )
|
||||||
shutdown();
|
shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
printWhy( int status )
|
||||||
|
{
|
||||||
|
if ( WIFEXITED(status) ) {
|
||||||
|
logf( XW_LOGINFO, "why: exited" );
|
||||||
|
} else if ( WIFSIGNALED(status) ) {
|
||||||
|
logf( XW_LOGINFO, "why: signaled" );
|
||||||
|
} else if ( WCOREDUMP(status) ) {
|
||||||
|
logf( XW_LOGINFO, "why: core" );
|
||||||
|
} else if ( WIFSTOPPED(status) ) {
|
||||||
|
logf( XW_LOGINFO, "why: traced" );
|
||||||
|
}
|
||||||
|
} /* printWhy */
|
||||||
|
|
||||||
int main( int argc, char** argv )
|
int main( int argc, char** argv )
|
||||||
{
|
{
|
||||||
int port = 0;
|
int port = 0;
|
||||||
|
@ -525,6 +540,22 @@ int main( int argc, char** argv )
|
||||||
PermID::SetServerName( serverName );
|
PermID::SetServerName( serverName );
|
||||||
PermID::SetIDFileName( idFileName );
|
PermID::SetIDFileName( idFileName );
|
||||||
|
|
||||||
|
/* loop forever, relaunching children as they die. */
|
||||||
|
for ( ; ; ) {
|
||||||
|
pid_t pid = fork();
|
||||||
|
if ( pid == 0 ) { /* child */
|
||||||
|
break;
|
||||||
|
} else if ( pid > 0 ) {
|
||||||
|
int status;
|
||||||
|
logf( XW_LOGINFO, "parent waiting on child pid=%d", pid );
|
||||||
|
waitpid( pid, &status, 0 );
|
||||||
|
printWhy( status );
|
||||||
|
sleep( 45 ); /* give time to close sockets? */
|
||||||
|
} else {
|
||||||
|
logf( XW_LOGERROR, "fork() => %s", strerror(errno) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g_listener = make_socket( INADDR_ANY, port );
|
g_listener = make_socket( INADDR_ANY, port );
|
||||||
if ( g_listener == -1 ) {
|
if ( g_listener == -1 ) {
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
|
|
Loading…
Reference in a new issue