threading: remove thread restart logic

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.
pull/2245/head
Victor Julien 9 years ago
parent 54503ef310
commit fb655d5f15

@ -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;

@ -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;
}

@ -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);

Loading…
Cancel
Save