]> git.stg.codes - stg.git/commitdiff
Block all signals in threads other than main
authorMaxim Mamontov <faust.madf@gmail.com>
Fri, 16 Sep 2011 17:44:06 +0000 (20:44 +0300)
committerMaxim Mamontov <faust.madf@gmail.com>
Fri, 16 Sep 2011 17:44:06 +0000 (20:44 +0300)
22 files changed:
projects/rscriptd/listener.cpp
projects/sgauth/web.cpp
projects/sgauthstress/proto.cpp
projects/stargazer/eventloop.cpp
projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp
projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp
projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp
projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp
projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp
projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp
projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp
projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp
projects/stargazer/plugins/other/ping/ping.cpp
projects/stargazer/plugins/other/radius/radius.cpp
projects/stargazer/plugins/other/rscript/rscript.cpp
projects/stargazer/plugins/other/smux/smux.cpp
projects/stargazer/stg_timer.cpp
projects/stargazer/traffcounter_impl.cpp
projects/stargazer/user_impl.cpp
projects/stargazer/users_impl.cpp
stglibs/ia.lib/ia.cpp
stglibs/pinger.lib/pinger.cpp

index d4f2dc937b56401519bca2dbdeffb546cf450639..730426744e50508556802c06d7bddcb81be91022 100644 (file)
@@ -165,6 +165,10 @@ return false;
 //-----------------------------------------------------------------------------
 void * LISTENER::Run(void * d)
 {
 //-----------------------------------------------------------------------------
 void * LISTENER::Run(void * d)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 LISTENER * listener = static_cast<LISTENER *>(d);
 
 listener->Runner();
 LISTENER * listener = static_cast<LISTENER *>(d);
 
 listener->Runner();
@@ -186,6 +190,10 @@ receiverStopped = true;
 //-----------------------------------------------------------------------------
 void * LISTENER::RunProcessor(void * d)
 {
 //-----------------------------------------------------------------------------
 void * LISTENER::RunProcessor(void * d)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 LISTENER * listener = static_cast<LISTENER *>(d);
 
 listener->ProcessorRunner();
 LISTENER * listener = static_cast<LISTENER *>(d);
 
 listener->ProcessorRunner();
index ab169cc49160f0813878ef7a7e1f65bce444f1f9..61cd2b5846211b4840465dde392c84db9ba62f2c 100644 (file)
  $Date: 2010/03/15 12:58:17 $
  */
 
  $Date: 2010/03/15 12:58:17 $
  */
 
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
 #include <libintl.h>
 
 #include <libintl.h>
 
+#include <csignal>
+#include <cstdio>
+#include <cstring>
+#include <ctime>
+
 #include "stg/common.h"
 #include "stg/ia.h"
 #include "web.h"
 #include "stg/common.h"
 #include "stg/ia.h"
 #include "web.h"
@@ -42,10 +44,15 @@ extern IA_CLIENT_PROT * clnp;
 //---------------------------------------------------------------------------
 #ifndef WIN32
 void * RunWeb(void *)
 //---------------------------------------------------------------------------
 #ifndef WIN32
 void * RunWeb(void *)
+{
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 #else
 unsigned long WINAPI RunWeb(void *)
 #else
 unsigned long WINAPI RunWeb(void *)
-#endif
 {
 {
+#endif
 while (1)
     web->Run();
 return NULL;
 while (1)
     web->Run();
 return NULL;
index 2e97fd2a0990c165c8d3089a0096866440f1a722..dc2bf08c1915e730be255fef5d1f6d91ad211f88 100644 (file)
@@ -1,6 +1,7 @@
 #include <netdb.h>
 #include <arpa/inet.h>
 
 #include <netdb.h>
 #include <arpa/inet.h>
 
+#include <csignal>
 #include <cerrno>
 #include <cstring>
 #include <cassert>
 #include <cerrno>
 #include <cstring>
 #include <cassert>
@@ -77,6 +78,10 @@ pthread_mutex_destroy(&mutex);
 
 void * PROTO::Runner(void * data)
 {
 
 void * PROTO::Runner(void * data)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 PROTO * protoPtr = static_cast<PROTO *>(data);
 protoPtr->Run();
 return NULL;
 PROTO * protoPtr = static_cast<PROTO *>(data);
 protoPtr->Run();
 return NULL;
index dd17de9b07a3c9ee6f488817b38fc9dcc8925adb..6cc59c94bde7d039c225e976d13adfbdf99181f1 100644 (file)
@@ -1,3 +1,4 @@
+#include <csignal>
 #include <cerrno>
 #include <cstring>
 
 #include <cerrno>
 #include <cstring>
 
@@ -53,6 +54,10 @@ return NULL;
 
 void EVENT_LOOP::Runner()
 {
 
 void EVENT_LOOP::Runner()
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 _stopped = false;
 printfd(__FILE__, "EVENT_LOOP::Runner - Before start\n");
 while (_running)
 _stopped = false;
 printfd(__FILE__, "EVENT_LOOP::Runner - Before start\n");
 while (_running)
index 4986080eb82a1b4c212e3a2a7b6bbef069bf6320..1eac0ab1f7fc462bfe72556aec021aaecff17593 100644 (file)
@@ -500,6 +500,10 @@ return 0;
 //-----------------------------------------------------------------------------
 void * AUTH_IA::Run(void * d)
 {
 //-----------------------------------------------------------------------------
 void * AUTH_IA::Run(void * d)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 AUTH_IA * ia = static_cast<AUTH_IA *>(d);
 
 ia->isRunningRun = true;
 AUTH_IA * ia = static_cast<AUTH_IA *>(d);
 
 ia->isRunningRun = true;
@@ -525,6 +529,10 @@ return NULL;
 //-----------------------------------------------------------------------------
 void * AUTH_IA::RunTimeouter(void * d)
 {
 //-----------------------------------------------------------------------------
 void * AUTH_IA::RunTimeouter(void * d)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 AUTH_IA * ia = static_cast<AUTH_IA *>(d);
 
 ia->isRunningRunTimeouter = true;
 AUTH_IA * ia = static_cast<AUTH_IA *>(d);
 
 ia->isRunningRunTimeouter = true;
index fb7d2cc5b0f291d4ffa846be6857008bb0e8499d..51ba49546d26fb7a4d8c9ee3be18b9be1b9750ac 100644 (file)
@@ -244,6 +244,10 @@ return false;
 
 void * NF_CAP::RunUDP(void * c)
 {
 
 void * NF_CAP::RunUDP(void * c)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 NF_CAP * cap = static_cast<NF_CAP *>(c);
 uint8_t buf[BUF_SIZE];
 int res;
 NF_CAP * cap = static_cast<NF_CAP *>(c);
 uint8_t buf[BUF_SIZE];
 int res;
@@ -286,6 +290,10 @@ return NULL;
 
 void * NF_CAP::RunTCP(void * c)
 {
 
 void * NF_CAP::RunTCP(void * c)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 NF_CAP * cap = static_cast<NF_CAP *>(c);
 uint8_t buf[BUF_SIZE];
 int res;
 NF_CAP * cap = static_cast<NF_CAP *>(c);
 uint8_t buf[BUF_SIZE];
 int res;
index 5927727e516a221dcc716bf87f58ef8258beaa9f..9a9d154300ae231a960b12bc0a1c4b8e30961064 100644 (file)
@@ -150,7 +150,11 @@ return 0;
 //-----------------------------------------------------------------------------
 void * DIVERT_CAP::Run(void * d)
 {
 //-----------------------------------------------------------------------------
 void * DIVERT_CAP::Run(void * d)
 {
-DIVERT_CAP * dc = (DIVERT_CAP *)d;
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
+DIVERT_CAP * dc = static_cast<DIVERT_CAP *>(d);
 dc->isRunning = true;
 
 char buffer[64];
 dc->isRunning = true;
 
 char buffer[64];
index 108c4e0d6a9e73cbb1c02123bb72003314b88f9d..5835d077acf6899b9c9cc3231d8d115e4d5c0209 100644 (file)
@@ -39,19 +39,20 @@ $Author: faust $
 #include <net/if.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <net/if.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-
-#include <errno.h>
 #include <fcntl.h>
 #include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <signal.h>
 #include <unistd.h>
 
 #include <unistd.h>
 
+#include <cerrno>
+#include <cstdio>
+#include <cstring>
+#include <cstdlib>
+#include <csignal>
+
 #include "stg/common.h"
 #include "stg/raw_ip_packet.h"
 #include "stg/traffcounter.h"
 #include "stg/plugin_creator.h"
 #include "stg/common.h"
 #include "stg/raw_ip_packet.h"
 #include "stg/traffcounter.h"
 #include "stg/plugin_creator.h"
+
 #include "ether_cap.h"
 
 //#define CAP_DEBUG 1
 #include "ether_cap.h"
 
 //#define CAP_DEBUG 1
@@ -201,7 +202,11 @@ return 0;
 //-----------------------------------------------------------------------------
 void * BPF_CAP::Run(void * d)
 {
 //-----------------------------------------------------------------------------
 void * BPF_CAP::Run(void * d)
 {
-BPF_CAP * dc = (BPF_CAP *)d;
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
+BPF_CAP * dc = static_cast<BPF_CAP *>(d);
 dc->isRunning = true;
 
 uint8_t hdr[96]; //68 + 14 + 4(size) + 9(SYS_IFACE) + 1(align to 4) = 96
 dc->isRunning = true;
 
 uint8_t hdr[96]; //68 + 14 + 4(size) + 9(SYS_IFACE) + 1(align to 4) = 96
index 276c8df0559876d43d4bc9376b1133f38cf641ca..632c18468f4f670061521f32615f64db8582e375 100644 (file)
@@ -32,22 +32,23 @@ $Date: 2009/12/13 13:45:13 $
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <sys/types.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <stdlib.h>
 #include <unistd.h>
 #include <linux/if_ether.h>
 #include <linux/if_packet.h>
 #include <unistd.h>
 #include <linux/if_ether.h>
 #include <linux/if_packet.h>
-#include <signal.h>
-
 #include <sys/ioctl.h>
 #include <net/if.h>
 
 #include <sys/ioctl.h>
 #include <net/if.h>
 
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <cerrno>
+#include <csignal>
+
 #include "stg/common.h"
 #include "stg/raw_ip_packet.h"
 #include "stg/traffcounter.h"
 #include "stg/plugin_creator.h"
 #include "stg/common.h"
 #include "stg/raw_ip_packet.h"
 #include "stg/traffcounter.h"
 #include "stg/plugin_creator.h"
+
 #include "ether_cap.h"
 
 //#define CAP_DEBUG 1
 #include "ether_cap.h"
 
 //#define CAP_DEBUG 1
@@ -149,6 +150,10 @@ return 0;
 //-----------------------------------------------------------------------------
 void * ETHER_CAP::Run(void * d)
 {
 //-----------------------------------------------------------------------------
 void * ETHER_CAP::Run(void * d)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 ETHER_CAP * dc = (ETHER_CAP *)d;
 dc->isRunning = true;
 
 ETHER_CAP * dc = (ETHER_CAP *)d;
 dc->isRunning = true;
 
index 84939b4e70e17e646bc8bf2a16025b64e8b45620..d0192e0ab65075dec4afeb209d223519c359b497 100644 (file)
 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
 */
 
 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
 */
 
-#include <signal.h>
-#include <cerrno>
 #include <netinet/in.h>
 #include <linux/netfilter.h>
 
 #include <netinet/in.h>
 #include <linux/netfilter.h>
 
+#include <csignal>
+#include <cerrno>
+
 #include "stg/raw_ip_packet.h"
 #include "stg/traffcounter.h"
 #include "stg/plugin_creator.h"
 #include "stg/raw_ip_packet.h"
 #include "stg/traffcounter.h"
 #include "stg/plugin_creator.h"
+
 #include "ipq_cap.h"
 
 extern "C"
 #include "ipq_cap.h"
 
 extern "C"
@@ -126,9 +128,13 @@ return 0;
 //-----------------------------------------------------------------------------
 void * IPQ_CAP::Run(void * d)
 {
 //-----------------------------------------------------------------------------
 void * IPQ_CAP::Run(void * d)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 RAW_PACKET raw_packet;
 
 RAW_PACKET raw_packet;
 
-IPQ_CAP * dc = (IPQ_CAP *)d;
+IPQ_CAP * dc = static_cast<IPQ_CAP *>(d);
 dc->isRunning = true;
 memset(&raw_packet, 0, sizeof(raw_packet));
 raw_packet.dataLen = -1;
 dc->isRunning = true;
 memset(&raw_packet, 0, sizeof(raw_packet));
 raw_packet.dataLen = -1;
index 837c86496dcabfbbfd56c59228477eb5015ec7dc..d3fdba55576f526cd4f292753fa86ffc5553e870 100644 (file)
@@ -157,6 +157,7 @@ if (!stopped)
         }
     if (!stopped)
         {
         }
     if (!stopped)
         {
+        running = true;
         printfd(__FILE__, "Failed to stop RPC thread\n");
         errorStr = "Failed to stop RPC thread";
         return -1;
         printfd(__FILE__, "Failed to stop RPC thread\n");
         errorStr = "Failed to stop RPC thread";
         return -1;
@@ -171,6 +172,10 @@ return 0;
 
 void * RPC_CONFIG::Run(void * rc)
 {
 
 void * RPC_CONFIG::Run(void * rc)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 RPC_CONFIG * config = static_cast<RPC_CONFIG *>(rc);
 
 config->stopped = false;
 RPC_CONFIG * config = static_cast<RPC_CONFIG *>(rc);
 
 config->stopped = false;
index 0a65c0d9c72a06b9f35dbd958c000af4ed472644..3cd6b9010f5ddd46ca5af4bcfe0d814b9271f039 100644 (file)
@@ -145,6 +145,10 @@ return 0;
 //-----------------------------------------------------------------------------
 void * STG_CONFIG::Run(void * d)
 {
 //-----------------------------------------------------------------------------
 void * STG_CONFIG::Run(void * d)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 STG_CONFIG * stgConf = (STG_CONFIG *)d;
 stgConf->isRunning = true;
 
 STG_CONFIG * stgConf = (STG_CONFIG *)d;
 stgConf->isRunning = true;
 
index c824067979e3243711ffe7f5e813b21692b0368c..f4755c230491f73cbec8e7f8c63e22b4ea9bc45f 100644 (file)
@@ -167,7 +167,11 @@ return isRunning;
 //-----------------------------------------------------------------------------
 void * PING::Run(void * d)
 {
 //-----------------------------------------------------------------------------
 void * PING::Run(void * d)
 {
-PING * ping = (PING *)d;
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
+PING * ping = static_cast<PING *>(d);
 ping->isRunning = true;
 
 long delay = (10000000 * ping->pingSettings.GetPingDelay()) / 3 + 50000000;
 ping->isRunning = true;
 
 long delay = (10000000 * ping->pingSettings.GetPingDelay()) / 3 + 50000000;
index 6a02ce4f3d7ff328779d41dee45a2df41eb676f3..c827330f0a7db7cd3791ef2a65d84cea6edd7327 100644 (file)
@@ -258,6 +258,10 @@ return 0;
 //-----------------------------------------------------------------------------
 void * RADIUS::Run(void * d)
 {
 //-----------------------------------------------------------------------------
 void * RADIUS::Run(void * d)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 RADIUS * rad = (RADIUS *)d;
 RAD_PACKET packet;
 
 RADIUS * rad = (RADIUS *)d;
 RAD_PACKET packet;
 
index c1d66051456d922e690b03f6edb8bd52db430398..175980066128a43085a2bcdbee9f8caa16c84a76 100644 (file)
@@ -198,6 +198,10 @@ pthread_mutex_destroy(&mutex);
 //-----------------------------------------------------------------------------
 void * REMOTE_SCRIPT::Run(void * d)
 {
 //-----------------------------------------------------------------------------
 void * REMOTE_SCRIPT::Run(void * d)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 REMOTE_SCRIPT * rs = static_cast<REMOTE_SCRIPT *>(d);
 
 rs->isRunning = true;
 REMOTE_SCRIPT * rs = static_cast<REMOTE_SCRIPT *>(d);
 
 rs->isRunning = true;
index 61ed80269f9bf9275460cb451c43d12f8575c761..5367e249b00c739fb548d772f852ae9f6789d8f0 100644 (file)
@@ -274,6 +274,10 @@ return 0;
 
 void * SMUX::Runner(void * d)
 {
 
 void * SMUX::Runner(void * d)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 SMUX * smux = static_cast<SMUX *>(d);
 
 smux->Run();
 SMUX * smux = static_cast<SMUX *>(d);
 
 smux->Run();
index fff79a3918de7ae93e1bb2258e7ebbd942919413..235c669e0df09dcea32c31d94e9b5347932b88ff 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <ctime>
 #include <cstring>
 
 #include <ctime>
 #include <cstring>
+#include <csignal>
 
 #include "stg/common.h"
 
 
 #include "stg/common.h"
 
@@ -58,6 +59,10 @@ switch (START_TIME)
 stgTime = time(NULL);
 #endif
 
 stgTime = time(NULL);
 #endif
 
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 nonstop = 1;
 isTimerRunning = true;
 while (nonstop)
 nonstop = 1;
 isTimerRunning = true;
 while (nonstop)
@@ -65,12 +70,10 @@ while (nonstop)
     #ifdef STG_TIMER_DEBUG
     struct timespec ts = {0, 1000000000 / TIME_SPEED};
     nanosleep(&ts, NULL);
     #ifdef STG_TIMER_DEBUG
     struct timespec ts = {0, 1000000000 / TIME_SPEED};
     nanosleep(&ts, NULL);
-    //usleep(1000000 / TIME_SPEED);
     stgTime++;
     #else
     struct timespec ts = {0, 500000000};
     nanosleep(&ts, NULL);
     stgTime++;
     #else
     struct timespec ts = {0, 500000000};
     nanosleep(&ts, NULL);
-    //usleep(500000);
     stgTime = time(NULL);
     #endif
     }
     stgTime = time(NULL);
     #endif
     }
@@ -112,11 +115,9 @@ int stgUsleep(unsigned long t)
 #ifdef STG_TIMER_DEBUG
 struct timespec ts = {(t / TIME_SPEED) / 1000000, ((t / TIME_SPEED) % 1000000) * 1000};
 return nanosleep(&ts, NULL);
 #ifdef STG_TIMER_DEBUG
 struct timespec ts = {(t / TIME_SPEED) / 1000000, ((t / TIME_SPEED) % 1000000) * 1000};
 return nanosleep(&ts, NULL);
-//return usleep(t / TIME_SPEED);
 #else
 struct timespec ts = {t / 1000000, (t % 1000000) * 1000};
 return nanosleep(&ts, NULL);
 #else
 struct timespec ts = {t / 1000000, (t % 1000000) * 1000};
 return nanosleep(&ts, NULL);
-//return usleep(t);
 #endif
 }
 //-----------------------------------------------------------------------------
 #endif
 }
 //-----------------------------------------------------------------------------
index ae7f1dfbc1a13ecd2596e452a47df7efb2b1403c..a02e3b6d520f2c0350cbd9eeec2b200a71088896 100644 (file)
@@ -169,6 +169,10 @@ return 0;
 //-----------------------------------------------------------------------------
 void * TRAFFCOUNTER_IMPL::Run(void * data)
 {
 //-----------------------------------------------------------------------------
 void * TRAFFCOUNTER_IMPL::Run(void * data)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 TRAFFCOUNTER_IMPL * tc = static_cast<TRAFFCOUNTER_IMPL *>(data);
 tc->stopped = false;
 int c = 0;
 TRAFFCOUNTER_IMPL * tc = static_cast<TRAFFCOUNTER_IMPL *>(data);
 tc->stopped = false;
 int c = 0;
index 6aca9cea06e69e4468f7f5303f844e52aa11882c..1278afa2de947124d604681a7617349cb3fa28f5 100644 (file)
@@ -484,7 +484,7 @@ for (int i = 0; i < DIR_NUM; i++)
     enabledDirs[i] = dirs & (1 << i);
     }
 
     enabledDirs[i] = dirs & (1 << i);
     }
 
-if (authorizedBy.size())
+if (!authorizedBy.empty())
     {
     if (currIP != ip)
         {
     {
     if (currIP != ip)
         {
index 19be5a4108ea134dd01185dcf31b5acfde5aa6bf..61ee90ff7e0ad6379f2f9faed6a3d1c7c4c10d74 100644 (file)
@@ -33,6 +33,7 @@
 #endif
 
 #include <pthread.h>
 #endif
 
 #include <pthread.h>
+
 #include <csignal>
 #include <cassert>
 #include <algorithm>
 #include <csignal>
 #include <cassert>
 #include <algorithm>
@@ -353,6 +354,10 @@ return 0;
 //-----------------------------------------------------------------------------
 void * USERS_IMPL::Run(void * d)
 {
 //-----------------------------------------------------------------------------
 void * USERS_IMPL::Run(void * d)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 printfd(__FILE__, "=====================| pid: %d |===================== \n", getpid());
 USERS_IMPL * us = (USERS_IMPL*) d;
 
 printfd(__FILE__, "=====================| pid: %d |===================== \n", getpid());
 USERS_IMPL * us = (USERS_IMPL*) d;
 
index abecef09f552fa4ff4f8a949402c4bc313e65429..81bd75fb7df8ec48b7bc198bb21642f2342af54f 100644 (file)
 #include <sys/time.h>
 void * RunL(void * data)
 {
 #include <sys/time.h>
 void * RunL(void * data)
 {
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
+
 
 IA_CLIENT_PROT * c = (IA_CLIENT_PROT *)data;
 static int a = 0;
 
 IA_CLIENT_PROT * c = (IA_CLIENT_PROT *)data;
 static int a = 0;
index df3793abab948d1178902388a3a0dd6103346df2..8e6370ed4774c257bb9aea21cc78208025bedfbd 100644 (file)
@@ -1,23 +1,25 @@
-#include <stdlib.h>
 #include <pthread.h>
 #include <pthread.h>
-#include <signal.h>
 #include <netdb.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <sys/time.h>
 #include <netdb.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <sys/time.h>
-#include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <errno.h>
-#include <math.h>
-#include <stdio.h>
 
 
-#include "pinger.h"
+#include <cstdlib>
+#include <csignal>
+#include <cstring>
+#include <cerrno>
+#include <cmath>
+#include <cstdio>
+
 #include "stg/common.h"
 #include "stg/locker.h"
 
 #include "stg/common.h"
 #include "stg/locker.h"
 
+#include "pinger.h"
+
 #ifdef STG_TIME
 extern volatile time_t stgTime;
 #endif
 #ifdef STG_TIME
 extern volatile time_t stgTime;
 #endif
@@ -40,320 +42,328 @@ STG_PINGER::STG_PINGER(time_t d)
       ipToDel(),
       mutex()
 {
       ipToDel(),
       mutex()
 {
-    pthread_mutex_init(&mutex, NULL);
-    memset(&pmSend, 0, sizeof(pmSend));
+pthread_mutex_init(&mutex, NULL);
+memset(&pmSend, 0, sizeof(pmSend));
 }
 //-----------------------------------------------------------------------------
 STG_PINGER::~STG_PINGER()
 {
 }
 //-----------------------------------------------------------------------------
 STG_PINGER::~STG_PINGER()
 {
-    pthread_mutex_destroy(&mutex);
+pthread_mutex_destroy(&mutex);
 }
 //-----------------------------------------------------------------------------
 int STG_PINGER::Start()
 {
 }
 //-----------------------------------------------------------------------------
 int STG_PINGER::Start()
 {
-    struct protoent *proto = NULL;
-    proto = getprotobyname("ICMP");
-    sendSocket = socket(PF_INET, SOCK_RAW, proto->p_proto);
-    recvSocket = socket(PF_INET, SOCK_RAW, proto->p_proto);
-    nonstop = true;
-    pid = (int) getpid() % 65535;
-    if (sendSocket < 0 || recvSocket < 0)
-        {
-        errorStr = "Cannot create socket.";
-        return -1;
-        }
+struct protoent *proto = NULL;
+proto = getprotobyname("ICMP");
+sendSocket = socket(PF_INET, SOCK_RAW, proto->p_proto);
+recvSocket = socket(PF_INET, SOCK_RAW, proto->p_proto);
+nonstop = true;
+pid = (int) getpid() % 65535;
+if (sendSocket < 0 || recvSocket < 0)
+    {
+    errorStr = "Cannot create socket.";
+    return -1;
+    }
 
 
-    if (pthread_create(&sendThread, NULL, RunSendPing, this))
-        {
-        errorStr = "Cannot create send thread.";
-        return -1;
-        }
+if (pthread_create(&sendThread, NULL, RunSendPing, this))
+    {
+    errorStr = "Cannot create send thread.";
+    return -1;
+    }
 
 
-    if (pthread_create(&recvThread, NULL, RunRecvPing, this))
-        {
-        errorStr = "Cannot create recv thread.";
-        return -1;
-        }
+if (pthread_create(&recvThread, NULL, RunRecvPing, this))
+    {
+    errorStr = "Cannot create recv thread.";
+    return -1;
+    }
 
 
-    return 0;
+return 0;
 }
 //-----------------------------------------------------------------------------
 int STG_PINGER::Stop()
 {
 }
 //-----------------------------------------------------------------------------
 int STG_PINGER::Stop()
 {
-    close(recvSocket);
-    nonstop = false;
-    if (isRunningRecver)
+close(recvSocket);
+nonstop = false;
+if (isRunningRecver)
+    {
+    //5 seconds to thread stops itself
+    for (size_t i = 0; i < 25; i++)
         {
         {
-        //5 seconds to thread stops itself
-        for (size_t i = 0; i < 25; i++)
-            {
-            if (i % 5 == 0)
-                SendPing(0x0100007f);//127.0.0.1
+        if (i % 5 == 0)
+            SendPing(0x0100007f);//127.0.0.1
 
 
-            if (!isRunningRecver)
-                break;
+        if (!isRunningRecver)
+            break;
 
 
-            struct timespec ts = {0, 200000000};
-            nanosleep(&ts, NULL);
-            }
+        struct timespec ts = {0, 200000000};
+        nanosleep(&ts, NULL);
+        }
 
 
-        //after 5 seconds waiting thread still running. now killing it
-        if (isRunningRecver)
+    //after 5 seconds waiting thread still running. now killing it
+    if (isRunningRecver)
+        {
+        if (pthread_kill(recvThread, SIGINT))
             {
             {
-            if (pthread_kill(recvThread, SIGINT))
-                {
-                errorStr = "Cannot kill thread.";
-                return -1;
-                }
+            errorStr = "Cannot kill thread.";
+            return -1;
             }
         }
             }
         }
+    }
 
 
-    if (isRunningSender)
+if (isRunningSender)
+    {
+    //5 seconds to thread stops itself
+    for (size_t i = 0; i < 25; i++)
         {
         {
-        //5 seconds to thread stops itself
-        for (size_t i = 0; i < 25; i++)
-            {
-            if (!isRunningSender)
-                break;
+        if (!isRunningSender)
+            break;
 
 
-            struct timespec ts = {0, 200000000};
-            nanosleep(&ts, NULL);
-            }
+        struct timespec ts = {0, 200000000};
+        nanosleep(&ts, NULL);
+        }
 
 
-        //after 5 seconds waiting thread still running. now killing it
-        if (isRunningSender)
+    //after 5 seconds waiting thread still running. now killing it
+    if (isRunningSender)
+        {
+        if (pthread_kill(sendThread, SIGINT))
             {
             {
-            if (pthread_kill(sendThread, SIGINT))
-                {
-                errorStr = "Cannot kill thread.";
-                return -1;
-                }
+            errorStr = "Cannot kill thread.";
+            return -1;
             }
         }
             }
         }
+    }
 
 
-    close(sendSocket);
-    return 0;
+close(sendSocket);
+return 0;
 }
 //-----------------------------------------------------------------------------
 void STG_PINGER::AddIP(uint32_t ip)
 {
 }
 //-----------------------------------------------------------------------------
 void STG_PINGER::AddIP(uint32_t ip)
 {
-    STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-    ipToAdd.push_back(ip);
+STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+ipToAdd.push_back(ip);
 }
 //-----------------------------------------------------------------------------
 void STG_PINGER::DelIP(uint32_t ip)
 {
 }
 //-----------------------------------------------------------------------------
 void STG_PINGER::DelIP(uint32_t ip)
 {
-    STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-    ipToDel.push_back(ip);
+STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+ipToDel.push_back(ip);
 }
 //-----------------------------------------------------------------------------
 void STG_PINGER::RealAddIP()
 }
 //-----------------------------------------------------------------------------
 void STG_PINGER::RealAddIP()
-    {
-    STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+{
+STG_LOCKER lock(&mutex, __FILE__, __LINE__);
 
 
-    std::list<uint32_t>::iterator iter;
-    iter = ipToAdd.begin();
-    while (iter != ipToAdd.end())
-        {
-        pingIP.insert(std::make_pair(*iter, 0));
-        ++iter;
-        }
-    ipToAdd.erase(ipToAdd.begin(), ipToAdd.end());
+std::list<uint32_t>::iterator iter;
+iter = ipToAdd.begin();
+while (iter != ipToAdd.end())
+    {
+    pingIP.insert(std::make_pair(*iter, 0));
+    ++iter;
     }
     }
+ipToAdd.erase(ipToAdd.begin(), ipToAdd.end());
+}
 //-----------------------------------------------------------------------------
 void STG_PINGER::RealDelIP()
 {
 //-----------------------------------------------------------------------------
 void STG_PINGER::RealDelIP()
 {
-    STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex, __FILE__, __LINE__);
 
 
-    std::list<uint32_t>::iterator iter;
-    std::multimap<uint32_t, time_t>::iterator treeIter;
-    iter = ipToDel.begin();
-    while (iter != ipToDel.end())
-        {
-        treeIter = pingIP.find(*iter);
-        if (treeIter != pingIP.end())
-            pingIP.erase(treeIter);
+std::list<uint32_t>::iterator iter;
+std::multimap<uint32_t, time_t>::iterator treeIter;
+iter = ipToDel.begin();
+while (iter != ipToDel.end())
+    {
+    treeIter = pingIP.find(*iter);
+    if (treeIter != pingIP.end())
+        pingIP.erase(treeIter);
 
 
-        ++iter;
-        }
-    ipToDel.erase(ipToDel.begin(), ipToDel.end());
+    ++iter;
+    }
+ipToDel.erase(ipToDel.begin(), ipToDel.end());
 }
 //-----------------------------------------------------------------------------
 int STG_PINGER::GetPingIPNum() const
 {
 }
 //-----------------------------------------------------------------------------
 int STG_PINGER::GetPingIPNum() const
 {
-    return pingIP.size();
+return pingIP.size();
 }
 //-----------------------------------------------------------------------------
 void STG_PINGER::PrintAllIP()
 {
 }
 //-----------------------------------------------------------------------------
 void STG_PINGER::PrintAllIP()
 {
-    STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-    std::multimap<uint32_t, time_t>::iterator iter;
-    iter = pingIP.begin();
-    while (iter != pingIP.end())
-        {
-        uint32_t ip = iter->first;
-        time_t t = iter->second;
-        std::string s;
-        x2str(t, s);
-        printf("ip = %s, time = %9s\n", inet_ntostring(ip).c_str(), s.c_str());
-        ++iter;
-        }
+STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+std::multimap<uint32_t, time_t>::iterator iter;
+iter = pingIP.begin();
+while (iter != pingIP.end())
+    {
+    uint32_t ip = iter->first;
+    time_t t = iter->second;
+    std::string s;
+    x2str(t, s);
+    printf("ip = %s, time = %9s\n", inet_ntostring(ip).c_str(), s.c_str());
+    ++iter;
+    }
 
 }
 //-----------------------------------------------------------------------------
 int STG_PINGER::GetIPTime(uint32_t ip, time_t * t) const
 {
 
 }
 //-----------------------------------------------------------------------------
 int STG_PINGER::GetIPTime(uint32_t ip, time_t * t) const
 {
-    STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-    std::multimap<uint32_t, time_t>::const_iterator treeIter;
+STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+std::multimap<uint32_t, time_t>::const_iterator treeIter;
 
 
-    treeIter = pingIP.find(ip);
-    if (treeIter == pingIP.end())
-        return -1;
+treeIter = pingIP.find(ip);
+if (treeIter == pingIP.end())
+    return -1;
 
 
-    *t = treeIter->second;
-    return 0;
+*t = treeIter->second;
+return 0;
 }
 //-----------------------------------------------------------------------------
 uint16_t STG_PINGER::PingCheckSum(void * data, int len)
 {
 }
 //-----------------------------------------------------------------------------
 uint16_t STG_PINGER::PingCheckSum(void * data, int len)
 {
-    unsigned short * buf = (unsigned short *)data;
-    unsigned int sum = 0;
-    unsigned short result;
+unsigned short * buf = (unsigned short *)data;
+unsigned int sum = 0;
+unsigned short result;
 
 
-    for ( sum = 0; len > 1; len -= 2 )
-        sum += *buf++;
+for ( sum = 0; len > 1; len -= 2 )
+    sum += *buf++;
 
 
-    if ( len == 1 )
-        sum += *(unsigned char*)buf;
+if ( len == 1 )
+    sum += *(unsigned char*)buf;
 
 
-    sum = (sum >> 16) + (sum & 0xFFFF);
-    sum += (sum >> 16);
-    result = ~sum;
-    return result;
+sum = (sum >> 16) + (sum & 0xFFFF);
+sum += (sum >> 16);
+result = ~sum;
+return result;
 }
 //-----------------------------------------------------------------------------
 int STG_PINGER::SendPing(uint32_t ip)
 {
 }
 //-----------------------------------------------------------------------------
 int STG_PINGER::SendPing(uint32_t ip)
 {
-    struct sockaddr_in addr;
-    memset(&addr, 0, sizeof(addr));
-    addr.sin_family = AF_INET;
-    addr.sin_port = 0;
-    addr.sin_addr.s_addr = ip;
+struct sockaddr_in addr;
+memset(&addr, 0, sizeof(addr));
+addr.sin_family = AF_INET;
+addr.sin_port = 0;
+addr.sin_addr.s_addr = ip;
 
 
-    memset(&pmSend, 0, sizeof(pmSend));
-    pmSend.hdr.type = ICMP_ECHO;
-    pmSend.hdr.un.echo.id = pid;
-    memcpy(pmSend.msg, &ip, sizeof(ip));
+memset(&pmSend, 0, sizeof(pmSend));
+pmSend.hdr.type = ICMP_ECHO;
+pmSend.hdr.un.echo.id = pid;
+memcpy(pmSend.msg, &ip, sizeof(ip));
 
 
-    pmSend.hdr.checksum = PingCheckSum(&pmSend, sizeof(pmSend));
+pmSend.hdr.checksum = PingCheckSum(&pmSend, sizeof(pmSend));
 
 
-    if (sendto(sendSocket, &pmSend, sizeof(pmSend), 0, (sockaddr *)&addr, sizeof(addr)) <= 0 )
-        {
-        errorStr = "Send ping error: " + std::string(strerror(errno));
-        return -1;
-        }
+if (sendto(sendSocket, &pmSend, sizeof(pmSend), 0, (sockaddr *)&addr, sizeof(addr)) <= 0 )
+    {
+    errorStr = "Send ping error: " + std::string(strerror(errno));
+    return -1;
+    }
 
 
 
 
-    return 0;
+return 0;
 }
 //-----------------------------------------------------------------------------
 uint32_t STG_PINGER::RecvPing()
 {
 }
 //-----------------------------------------------------------------------------
 uint32_t STG_PINGER::RecvPing()
 {
-    struct sockaddr_in addr;
-    uint32_t ipAddr = 0;
+struct sockaddr_in addr;
+uint32_t ipAddr = 0;
 
 
-    char buf[128];
-    memset(buf, 0, sizeof(buf));
-    int bytes;
-    socklen_t len = sizeof(addr);
+char buf[128];
+memset(buf, 0, sizeof(buf));
+int bytes;
+socklen_t len = sizeof(addr);
 
 
-    bytes = recvfrom(recvSocket, &buf, sizeof(buf), 0, (struct sockaddr*)&addr, &len);
-    if (bytes > 0)
-        {
-        struct IP_HDR * ip = (struct IP_HDR *)buf;
-        struct ICMP_HDR *icmp = (struct ICMP_HDR *)(buf + ip->ihl * 4);
+bytes = recvfrom(recvSocket, &buf, sizeof(buf), 0, (struct sockaddr*)&addr, &len);
+if (bytes > 0)
+    {
+    struct IP_HDR * ip = (struct IP_HDR *)buf;
+    struct ICMP_HDR *icmp = (struct ICMP_HDR *)(buf + ip->ihl * 4);
 
 
-        if (icmp->un.echo.id != pid)
-            return 0;
+    if (icmp->un.echo.id != pid)
+        return 0;
 
 
-        ipAddr = *(uint32_t*)(buf + sizeof(ICMP_HDR) + ip->ihl * 4);
-        }
+    ipAddr = *(uint32_t*)(buf + sizeof(ICMP_HDR) + ip->ihl * 4);
+    }
 
 
-    return ipAddr;
+return ipAddr;
 }
 //-----------------------------------------------------------------------------
 void * STG_PINGER::RunSendPing(void * d)
 {
 }
 //-----------------------------------------------------------------------------
 void * STG_PINGER::RunSendPing(void * d)
 {
-    STG_PINGER * pinger = static_cast<STG_PINGER *>(d);
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
 
 
-    pinger->isRunningSender = true;
-    time_t lastPing = 0;
-    while (pinger->nonstop)
+STG_PINGER * pinger = static_cast<STG_PINGER *>(d);
+
+pinger->isRunningSender = true;
+time_t lastPing = 0;
+while (pinger->nonstop)
+    {
+    pinger->RealAddIP();
+    pinger->RealDelIP();
+
+    std::multimap<uint32_t, time_t>::iterator iter;
+    iter = pinger->pingIP.begin();
+    while (iter != pinger->pingIP.end())
         {
         {
-        pinger->RealAddIP();
-        pinger->RealDelIP();
+        pinger->SendPing(iter->first);
+        ++iter;
+        }
 
 
-        std::multimap<uint32_t, time_t>::iterator iter;
-        iter = pinger->pingIP.begin();
-        while (iter != pinger->pingIP.end())
-            {
-            pinger->SendPing(iter->first);
-            ++iter;
-            }
+    time_t currTime;
 
 
-        time_t currTime;
+    #ifdef STG_TIME
+    lastPing = stgTime;
+    currTime = stgTime;
+    #else
+    currTime = lastPing = time(NULL);
+    #endif
 
 
+    while (currTime - lastPing < pinger->delay && pinger->nonstop)
+        {
         #ifdef STG_TIME
         #ifdef STG_TIME
-        lastPing = stgTime;
         currTime = stgTime;
         #else
         currTime = stgTime;
         #else
-        currTime = lastPing = time(NULL);
+        currTime = time(NULL);
         #endif
         #endif
-
-        while (currTime - lastPing < pinger->delay && pinger->nonstop)
-            {
-            #ifdef STG_TIME
-            currTime = stgTime;
-            #else
-            currTime = time(NULL);
-            #endif
-            struct timespec ts = {0, 20000000};
-            nanosleep(&ts, NULL);
-            }
+        struct timespec ts = {0, 20000000};
+        nanosleep(&ts, NULL);
         }
         }
+    }
 
 
-    pinger->isRunningSender = false;
+pinger->isRunningSender = false;
 
 
-    return NULL;
+return NULL;
 }
 //-----------------------------------------------------------------------------
 void * STG_PINGER::RunRecvPing(void * d)
 {
 }
 //-----------------------------------------------------------------------------
 void * STG_PINGER::RunRecvPing(void * d)
 {
-    STG_PINGER * pinger = static_cast<STG_PINGER *>(d);
+sigset_t signalSet;
+sigfillset(&signalSet);
+pthread_sigmask(SIG_BLOCK, &signalSet, NULL);
 
 
-    pinger->isRunningRecver = true;
+STG_PINGER * pinger = static_cast<STG_PINGER *>(d);
 
 
-    while (pinger->nonstop)
-        {
-        uint32_t ip = pinger->RecvPing();
+pinger->isRunningRecver = true;
+
+while (pinger->nonstop)
+    {
+    uint32_t ip = pinger->RecvPing();
 
 
-        if (ip)
+    if (ip)
+        {
+        std::multimap<uint32_t, time_t>::iterator treeIterUpper = pinger->pingIP.upper_bound(ip);
+        std::multimap<uint32_t, time_t>::iterator treeIterLower = pinger->pingIP.lower_bound(ip);
+        while (treeIterUpper != treeIterLower)
             {
             {
-            std::multimap<uint32_t, time_t>::iterator treeIterUpper = pinger->pingIP.upper_bound(ip);
-            std::multimap<uint32_t, time_t>::iterator treeIterLower = pinger->pingIP.lower_bound(ip);
-            while (treeIterUpper != treeIterLower)
-                {
-                #ifdef STG_TIME
-                treeIterLower->second = stgTime;
-                #else
-                treeIterLower->second = time(NULL);
-                #endif
-                ++treeIterLower;
-                }
+            #ifdef STG_TIME
+            treeIterLower->second = stgTime;
+            #else
+            treeIterLower->second = time(NULL);
+            #endif
+            ++treeIterLower;
             }
             }
-
         }
         }
-    pinger->isRunningRecver = false;
-    return NULL;
+
+    }
+pinger->isRunningRecver = false;
+return NULL;
 }
 //-----------------------------------------------------------------------------
 }
 //-----------------------------------------------------------------------------