Commit dba21fbf authored by Pavel Vainerman's avatar Pavel Vainerman

(extensions): вынес общий код функцит on_sigchild(..);

(ожидание завершения дочерних потоков)
parent 3e5e880b
#include <sys/wait.h>
#include <sstream>
#include "MBTCPMaster.h"
#include "Configuration.h"
......@@ -70,7 +69,7 @@ int main( int argc, const char** argv )
dlog << "\n\n\n";
dlog << "(main): -------------- MBTCP Exchange START -------------------------\n\n";
act->run(false);
while( waitpid(-1, 0, 0) > 0 );
on_sigchild(SIGTERM);
return 0;
}
catch( Exception& ex )
......@@ -82,6 +81,6 @@ int main( int argc, const char** argv )
dcrit << "(mbtcpmaster): catch ..." << std::endl;
}
while( waitpid(-1, 0, 0) > 0 );
on_sigchild(SIGTERM);
return 1;
}
#include <sys/wait.h>
#include <sstream>
#include "MBTCPMultiMaster.h"
#include "Configuration.h"
......@@ -71,7 +70,7 @@ int main( int argc, const char** argv )
dlog << "(main): -------------- MBTCPMulti Exchange START -------------------------\n\n";
act->run(false);
while( waitpid(-1, 0, 0) > 0 );
on_sigchild(SIGTERM);
return 0;
}
......@@ -84,6 +83,6 @@ int main( int argc, const char** argv )
dcrit << "(mbtcpmultimaster): catch ..." << std::endl;
}
while( waitpid(-1, 0, 0) > 0 );
on_sigchild(SIGTERM);
return 1;
}
#include <sys/wait.h>
#include <sstream>
#include "UniSetActivator.h"
#include "Extensions.h"
......@@ -70,7 +69,7 @@ int main( int argc, char** argv )
act->run(false);
while( waitpid(-1, 0, 0) > 0 );
on_sigchild(SIGTERM);
return 0;
}
catch( Exception& ex )
......@@ -82,6 +81,6 @@ int main( int argc, char** argv )
dcrit << "(rtuexchange): catch ..." << std::endl;
}
while( waitpid(-1, 0, 0) > 0 );
on_sigchild(SIGTERM);
return 1;
}
// --------------------------------------------------------------------------
#include <sys/wait.h>
#include <sstream>
#include <string>
#include <cc++/socket.h>
......@@ -75,7 +74,7 @@ int main(int argc, const char **argv)
dlog << "(main): -------------- MBSlave START -------------------------\n\n";
act->run(false);
while( waitpid(-1, 0, 0) > 0 );
on_sigchild(SIGTERM);
return 0;
}
catch( SystemError& err )
......@@ -95,7 +94,7 @@ int main(int argc, const char **argv)
dcrit << "(mbslave): catch(...)" << endl;
}
while( waitpid(-1, 0, 0) > 0 );
on_sigchild(SIGTERM);
return 1;
}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
#include <sys/wait.h>
#include <sstream>
#include <string>
#include <cc++/socket.h>
......@@ -75,7 +74,7 @@ int main(int argc, const char **argv)
dlog << "(main): -------------- MBTCPMultiSlave START -------------------------\n\n";
act->run(false);
while( waitpid(-1, 0, 0) > 0 );
on_sigchild(SIGTERM);
return 0;
}
catch( SystemError& err )
......@@ -95,7 +94,7 @@ int main(int argc, const char **argv)
dcrit << "(mbslave): catch(...)" << endl;
}
while( waitpid(-1, 0, 0) > 0 );
on_sigchild(SIGTERM);
return 1;
}
// --------------------------------------------------------------------------
......@@ -38,8 +38,6 @@ int main(int argc, const char **argv)
SystemMessage sm(SystemMessage::StartUp);
act->broadcast( sm.transport_msg() );
act->run(false);
// pause(); // пауза, чтобы дочерние потоки успели завершить работу
return 0;
}
catch( SystemError& err )
......
// --------------------------------------------------------------------------
#include <string>
#include <sys/wait.h>
#include <error.h>
#include <errno.h>
#include <Debug.h>
......@@ -22,18 +21,6 @@ using namespace UniSetExtensions;
// --------------------------------------------------------------------------
const int MaxAddNum = 10;
// --------------------------------------------------------------------------
void on_sigchild( int sig )
{
// while( waitpid(0,NULL,WNOHANG) > 0 ){}
while(1)
{
int istatus;
pid_t pid = waitpid( -1, &istatus, WNOHANG );
if( pid == -1 && errno == EINTR ) continue;
if( pid <= 0 ) break;
}
}
// --------------------------------------------------------------------------
static void help_print( int argc, const char* argv[] );
// --------------------------------------------------------------------------
int main( int argc, const char **argv )
......
#include <sstream>
#include <sys/wait.h>
#include "UniSetActivator.h"
#include "Extensions.h"
#include "UNetExchange.h"
......@@ -68,7 +67,7 @@ int main( int argc, const char** argv )
dlog << "(main): -------------- UDPReceiver START -------------------------\n\n";
act->run(false);
while( waitpid(-1, 0, 0) > 0 );
on_sigchild(SIGTERM);
}
catch( Exception& ex )
{
......@@ -79,6 +78,6 @@ int main( int argc, const char** argv )
dcrit << "(unetexchange): catch ..." << std::endl;
}
while( waitpid(-1, 0, 0) > 0 );
on_sigchild(SIGTERM);
return 0;
}
#include <sys/wait.h>
#include <string>
#include "Debug.h"
#include "UniSetActivator.h"
......@@ -53,7 +52,7 @@ int main(int argc, const char **argv)
act->broadcast( sm.transport_msg() );
act->run(true);
shm->execute();
while( waitpid(-1, 0, 0) > 0 );
on_sigchild(SIGTERM);
return 0;
}
catch(SystemError& err)
......@@ -69,6 +68,6 @@ int main(int argc, const char **argv)
dlog.crit() << "(uninetwork): catch(...)" << endl;
}
while( waitpid(-1, 0, 0) > 0 );
on_sigchild(SIGTERM);
return 1;
}
......@@ -28,6 +28,9 @@ namespace UniSetExtensions
/*! Загрузка калибровочной диаграммы */
Calibration* buildCalibrationDiagram( const std::string& dname );
void on_sigchild( int sig );
extern DebugStream dlog;
}
// -------------------------------------------------------------------------
......
#include <sstream>
#include <string>
#include <sys/wait.h>
#include "Configuration.h"
#include "Extensions.h"
// -------------------------------------------------------------------------
......@@ -128,6 +129,17 @@ namespace UniSetExtensions
return new Calibration(dnode);
}
// -------------------------------------------------------------------------
void on_sigchild( int sig )
{
while(1)
{
int istatus;
pid_t pid = waitpid( -1, &istatus, WNOHANG );
if( pid == -1 && errno == EINTR ) continue;
if( pid <= 0 ) break;
}
}
// --------------------------------------------------------------------------
} // end of namespace
// -------------------------------------------------------------------------
......@@ -360,7 +360,6 @@ void ModbusTCPMaster::connect( ost::InetAddress addr, int _port )
ost::Thread::setException(ost::Thread::throwException);
try
{
ostringstream aa;
tcp = new UTCPStream();
tcp->create(iaddr,port,true,500);
tcp->setTimeout(replyTimeOut_ms);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment