]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
threading: remove thread restart logic
authorVictor Julien <victor@inliniac.net>
Wed, 13 Jul 2016 19:07:11 +0000 (21:07 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 19 Sep 2016 10:51:09 +0000 (12:51 +0200)
Thread restarts never worked well and the rest of the engine was
never really expecting errors to lead to thread restarts. Either
and error is recoverable in the thread, or not at all.

So this patch removes the functionality completely.

src/threadvars.h
src/tm-threads.c
src/tm-threads.h

index c72dcc734ddbfe4d45c66e44b6ea9adccc9d63d6..389f22a14eaabea48fa76ec2df40e905749ae023 100644 (file)
@@ -53,14 +53,6 @@ struct TmSlot_;
  *  rule reloads even if no packets are read by the capture method. */
 #define THV_CAPTURE_INJECT_PKT (1<<11)
 
-/** Thread flags set and read by threads, to control the threads, when they
- *  encounter certain conditions like failure */
-#define THV_RESTART_THREAD 0x01 /** restart the thread */
-#define THV_ENGINE_EXIT 0x02 /** shut the engine down gracefully */
-
-/** Maximum no of times a thread can be restarted */
-#define THV_MAX_RESTARTS 50
-
 /** \brief Per thread variable structure */
 typedef struct ThreadVars_ {
     pthread_t t;
@@ -69,13 +61,6 @@ typedef struct ThreadVars_ {
 
     SC_ATOMIC_DECLARE(unsigned int, flags);
 
-    /** aof(action on failure) determines what should be done with the thread
-        when it encounters certain conditions like failures */
-    uint8_t aof;
-
-    /** no of times the thread has been restarted on failure */
-    uint8_t restarted;
-
     /** TmModule::flags for each module part of this thread */
     uint8_t tmm_flags;
 
index 08fb6429ee7c7d67029c07cf272545a0da9d568c..fa84364963cc8d024c8b0f6317c7a0c02c00f65e 100644 (file)
@@ -81,10 +81,6 @@ ThreadVars *tv_root[TVT_MAX] = { NULL };
 /* lock to protect tv_root */
 SCMutex tv_root_lock = SCMUTEX_INITIALIZER;
 
-/* Action On Failure(AOF).  Determines how the engine should behave when a
- * thread encounters a failure.  Defaults to restart the failed thread */
-uint8_t tv_aof = THV_RESTART_THREAD;
-
 /**
  * \brief Check if a thread flag is set.
  *
@@ -1171,8 +1167,6 @@ ThreadVars *TmThreadCreate(const char *name, char *inq_name, char *inqh_name,
     /* default state for every newly created thread */
     TmThreadsSetFlag(tv, THV_PAUSE);
     TmThreadsSetFlag(tv, THV_USE);
-    /* default aof for every newly created thread */
-    tv->aof = THV_RESTART_THREAD;
 
     /* set the incoming queue */
     if (inq_name != NULL && strcmp(inq_name, "packetpool") != 0) {
@@ -1879,19 +1873,6 @@ void TmThreadSetFlags(ThreadVars *tv, uint8_t flags)
     return;
 }
 #endif
-/**
- * \brief Sets the aof(Action on failure) for a thread instance(tv)
- *
- * \param tv  Pointer to the thread instance for which the aof has to be set
- * \param aof Holds the aof this thread instance has to be set to
- */
-void TmThreadSetAOF(ThreadVars *tv, uint8_t aof)
-{
-    if (tv != NULL)
-        tv->aof = aof;
-
-    return;
-}
 
 /**
  * \brief Initializes the mutex and condition variables for this TV
@@ -2046,38 +2027,7 @@ void TmThreadPauseThreads()
 }
 
 /**
- * \brief Restarts the thread sent as the argument
- *
- * \param tv Pointer to the thread instance(tv) to be restarted
- */
-static void TmThreadRestartThread(ThreadVars *tv)
-{
-    if (tv->restarted >= THV_MAX_RESTARTS) {
-        SCLogError(SC_ERR_TM_THREADS_ERROR,"thread restarts exceeded "
-                "threshold limit for thread \"%s\"", tv->name);
-        exit(EXIT_FAILURE);
-    }
-
-    TmThreadsUnsetFlag(tv, THV_CLOSED);
-    TmThreadsUnsetFlag(tv, THV_FAILED);
-
-    if (TmThreadSpawn(tv) != TM_ECODE_OK) {
-        SCLogError(SC_ERR_THREAD_SPAWN, "thread \"%s\" failed to spawn", tv->name);
-        exit(EXIT_FAILURE);
-    }
-
-    tv->restarted++;
-    SCLogInfo("thread \"%s\" restarted", tv->name);
-
-    return;
-}
-
-/**
- * \brief Used to check the thread for certain conditions of failure.  If the
- *        thread has been specified to restart on failure, the thread is
- *        restarted.  If the thread has been specified to gracefully shutdown
- *        the engine on failure, it does so.  The global aof flag, tv_aof
- *        overrides the thread aof flag, if it holds a THV_ENGINE_EXIT;
+ * \brief Used to check the thread for certain conditions of failure.
  */
 void TmThreadCheckThreadState(void)
 {
@@ -2091,19 +2041,8 @@ void TmThreadCheckThreadState(void)
         while (tv) {
             if (TmThreadsCheckFlag(tv, THV_FAILED)) {
                 TmThreadsSetFlag(tv, THV_DEINIT);
-                pthread_join(tv->t, NULL);
-                if ((tv_aof & THV_ENGINE_EXIT) || (tv->aof & THV_ENGINE_EXIT)) {
-                    EngineKill();
-                    goto end;
-                } else {
-                    /* if the engine kill-stop has been received by now, chuck
-                     * restarting and return to kill the engine */
-                    if ((suricata_ctl_flags & SURICATA_KILL) ||
-                        (suricata_ctl_flags & SURICATA_STOP)) {
-                        goto end;
-                    }
-                    TmThreadRestartThread(tv);
-                }
+                EngineKill();
+                goto end;
             }
             tv = tv->next;
         }
index 1942ae1ce54a388fc3e19432557cdebe99f27865..943b6236a9b8d8abaaa9a33afb94aab734f6c766 100644 (file)
@@ -95,7 +95,6 @@ ThreadVars *TmThreadCreateCmdThreadByName(const char *name, char *module,
                                      int mucond);
 TmEcode TmThreadSpawn(ThreadVars *);
 void TmThreadSetFlags(ThreadVars *, uint8_t);
-void TmThreadSetAOF(ThreadVars *, uint8_t);
 void TmThreadKillThread(ThreadVars *);
 void TmThreadKillThreadsFamily(int family);
 void TmThreadKillThreads(void);