Permalink
Browse files

Revert "try to restart the server if a child dies"

It's not ready for release yet. Desirable, but still problematic.

This reverts commit 57361db.
  • Loading branch information...
1 parent 3645f2f commit 6256fc7af77d7c961be95baa07794f6077384b4d Abhijit Menon-Sen committed Apr 13, 2009
Showing with 27 additions and 52 deletions.
  1. +27 −52 server/server.cpp
View
@@ -22,9 +22,6 @@
#include <stdio.h>
// sigaction, sigemptyset
#include <signal.h>
-// waitpid()
-#include <sys/types.h>
-#include <sys/wait.h>
// our own includes, _after_ the system header files. lots of system
// header files break if we've already defined UINT_MAX, etc.
@@ -406,61 +403,39 @@ void Server::fork()
} else if ( p > 0 ) {
exit( 0 );
}
-
d->mainProcess = true;
- d->children = new List<pid_t>;
- uint children = 1;
- if ( d->name == "archiveopteryx" )
+ uint children = 0;
+ if ( d->name == "archiveopteryx" ) {
children = Configuration::scalar( Configuration::ServerProcesses );
- uint i = 0;
- while ( i < children ) {
- d->children->append( new pid_t( 0 ) );
- i++;
+ if ( children > 1 )
+ d->children = new List<pid_t>;
}
- while ( d->mainProcess ) {
- List<pid_t>::Iterator c( d->children );
- while ( c ) {
- if ( *c ) {
- int r = ::kill( *c, 0 );
- if ( r < 0 && errno == ESRCH )
- *c = 0;
- }
- ++c;
+ uint i = 1;
+ while ( d->children && i < children ) {
+ pid_t * child = new pid_t;
+ *child = ::fork();
+ if ( *child < 0 ) {
+ log( "Unable to fork server; pressing on. Error code " +
+ fn( errno ), Log::Error );
}
- c = d->children->first();
- uint i = 0;
- while ( c && d->mainProcess ) {
- if ( !*c ) {
- *c = ::fork();
- if ( *c < 0 ) {
- log( "Unable to fork server; pressing on. Error code " +
- fn( errno ), Log::Error );
- *c = 0;
- }
- else if ( *c > 0 ) {
- // the parent, all is well
- }
- else {
- // a child. fork() must return.
- d->mainProcess = false;
- }
+ else if ( *child > 0 ) {
+ log( "Process " + fn( getpid() ) + " forked " + fn( *child ) );
+ d->children->append( child );
+ }
+ else {
+ d->mainProcess = false;
+ d->children = 0;
+ EventLoop::global()->closeAllExceptListeners();
+ log( "Process " + fn( getpid() ) + " started" );
+ if ( Configuration::toggle( Configuration::UseStatistics ) ) {
+ uint port
+ = Configuration::scalar( Configuration::StatisticsPort );
+ log( "Using port " + fn( port + i ) +
+ " for statistics queries" );
+ Configuration::add( "statistics-port = " + fn( port + i ) );
}
- ++i;
- ++c;
}
- int status = 0;
- ::waitpid( -1, &status, 0 );
- }
-
- // only a child gets this far
- d->children = 0;
- EventLoop::global()->closeAllExceptListeners();
- log( "Process " + fn( getpid() ) + " started" );
- if ( Configuration::toggle( Configuration::UseStatistics ) ) {
- uint port = Configuration::scalar( Configuration::StatisticsPort );
- log( "Using port " + fn( port + i - 1 ) +
- " for statistics queries" );
- Configuration::add( "statistics-port = " + fn( port + i - 1 ) );
+ i++;
}
}

0 comments on commit 6256fc7

Please sign in to comment.