Commit dba21fbf authored by Pavel Vainerman's avatar Pavel Vainerman

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

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