]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp
Block all signals in threads other than main
[stg.git] / projects / stargazer / plugins / authorization / inetaccess / inetaccess.cpp
index 9fc12ecce23c54bb30ce4d65d3fb7a0313cf69ca..1eac0ab1f7fc462bfe72556aec021aaecff17593 100644 (file)
@@ -30,7 +30,7 @@
 
 #include <sys/types.h>
 #include <sys/socket.h>
-#include <unistd.h> // usleep, close
+#include <unistd.h> // close
 
 #include <csignal>
 #include <cstdlib>
@@ -70,6 +70,7 @@ AUTH_IA_SETTINGS::AUTH_IA_SETTINGS()
     : userDelay(0),
       userTimeout(0),
       port(0),
+      errorStr(),
       freeMbShowType(freeMbCash)
 {
 }
@@ -173,13 +174,15 @@ return 0;
 #ifdef IA_PHASE_DEBUG
 IA_PHASE::IA_PHASE()
     : phase(1),
+      phaseTime(),
       flog(NULL)
 {
 gettimeofday(&phaseTime, NULL);
 }
 #else
 IA_PHASE::IA_PHASE()
-    : phase(1)
+    : phase(1),
+      phaseTime()
 {
 gettimeofday(&phaseTime, NULL);
 }
@@ -295,12 +298,29 @@ return phaseTime;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 AUTH_IA::AUTH_IA()
-    : nonstop(false),
+    : ctxS(),
+      errorStr(),
+      iaSettings(),
+      settings(),
+      nonstop(false),
       isRunningRun(false),
       isRunningRunTimeouter(false),
       users(NULL),
       stgSettings(NULL),
+      ip2user(),
+      recvThread(),
+      timeouterThread(),
+      mutex(),
       listenSocket(-1),
+      connSynAck6(),
+      connSynAck8(),
+      disconnSynAck6(),
+      disconnSynAck8(),
+      aliveSyn6(),
+      aliveSyn8(),
+      fin6(),
+      fin8(),
+      packetTypes(),
       WriteServLog(GetStgLogger()),
       enabledDirs(0xFFffFFff),
       onDelUserNotifier(*this)
@@ -408,7 +428,8 @@ if (isRunningRun)
     //5 seconds to thread stops itself
     for (int i = 0; i < 25 && isRunningRun; i++)
         {
-        usleep(200000);
+        struct timespec ts = {0, 200000000};
+        nanosleep(&ts, NULL);
         }
 
     //after 5 seconds waiting thread still running. now killing it
@@ -421,7 +442,10 @@ if (isRunningRun)
             return -1;
             }
         for (int i = 0; i < 25 && isRunningRun; ++i)
-            usleep(200000);
+            {
+            struct timespec ts = {0, 200000000};
+            nanosleep(&ts, NULL);
+            }
         if (isRunningRun)
             {
             printfd(__FILE__, "Failed to stop recv thread\n");
@@ -441,7 +465,8 @@ if (isRunningRunTimeouter)
     //5 seconds to thread stops itself
     for (int i = 0; i < 25 && isRunningRunTimeouter; i++)
         {
-        usleep(200000);
+        struct timespec ts = {0, 200000000};
+        nanosleep(&ts, NULL);
         }
 
     //after 5 seconds waiting thread still running. now killing it
@@ -453,7 +478,10 @@ if (isRunningRunTimeouter)
             return -1;
             }
         for (int i = 0; i < 25 && isRunningRunTimeouter; ++i)
-            usleep(200000);
+            {
+            struct timespec ts = {0, 200000000};
+            nanosleep(&ts, NULL);
+            }
         if (isRunningRunTimeouter)
             {
             printfd(__FILE__, "Failed to stop timeouter thread\n");
@@ -472,6 +500,10 @@ return 0;
 //-----------------------------------------------------------------------------
 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;
@@ -497,6 +529,10 @@ return NULL;
 //-----------------------------------------------------------------------------
 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;
@@ -505,7 +541,8 @@ int a = -1;
 string monFile = ia->stgSettings->GetMonitorDir() + "/inetaccess_t";
 while (ia->nonstop)
     {
-    usleep(20000);
+    struct timespec ts = {0, 20000000};
+    nanosleep(&ts, NULL);
     ia->Timeouter();
     // TODO change counter to timer and MONITOR_TIME_DELAY_SEC
     if (++a % (50 * 60) == 0 && ia->stgSettings->GetMonitoring())