switch (-r) {
case AFP_FATAL_ERROR:
SCLogError(SC_ERR_AFP_CREATE, "Couldn't init AF_PACKET socket, fatal error");
- /* fatal is fatal, we want suri to exit */
- EngineKill();
- //tv->aof = THV_ENGINE_EXIT;
SCReturnInt(TM_ECODE_FAILED);
case AFP_RECOVERABLE_ERROR:
SCLogWarning(SC_ERR_AFP_CREATE, "Couldn't init AF_PACKET socket, retrying soon");
dtv->slot = s->slot_next;
while (1) {
- if (suricata_ctl_flags & (SURICATA_STOP | SURICATA_KILL)) {
+ if (suricata_ctl_flags & SURICATA_STOP) {
SCReturnInt(TM_ECODE_OK);
}
etv->slot = ((TmSlot *)slot)->slot_next;
while (1) {
- if (suricata_ctl_flags & (SURICATA_STOP | SURICATA_KILL)) {
+ if (suricata_ctl_flags & SURICATA_STOP) {
SCReturnInt(TM_ECODE_OK);
}
TmSlot *s = (TmSlot *)slot;
ntv->slot = s->slot_next;
- while (!(suricata_ctl_flags & (SURICATA_STOP | SURICATA_KILL))) {
+ while (!(suricata_ctl_flags & SURICATA_STOP)) {
/* make sure we have at least one packet in the packet pool, to prevent
* us from alloc'ing packets at line rate */
PacketPoolWait();
ptv->cb_result = TM_ECODE_OK;
while (1) {
- if (suricata_ctl_flags & (SURICATA_STOP | SURICATA_KILL)) {
+ if (suricata_ctl_flags & SURICATA_STOP) {
SCReturnInt(TM_ECODE_OK);
}
if (unlikely(r == -1)) {
SCLogError(SC_ERR_PCAP_DISPATCH, "error code %" PRId32 " %s",
r, pcap_geterr(pcap_g.pcap_handle));
- if (! RunModeUnixSocketIsActive()) {
- /* in the error state we just kill the engine */
- EngineKill();
+ if (ptv->cb_result == TM_ECODE_FAILED) {
SCReturnInt(TM_ECODE_FAILED);
+ }
+ if (! RunModeUnixSocketIsActive()) {
+ EngineStop();
} else {
pcap_close(pcap_g.pcap_handle);
pcap_g.pcap_handle = NULL;
} else if (ptv->cb_result == TM_ECODE_FAILED) {
SCLogError(SC_ERR_PCAP_DISPATCH, "Pcap callback PcapFileCallbackLoop failed");
if (! RunModeUnixSocketIsActive()) {
- EngineKill();
SCReturnInt(TM_ECODE_FAILED);
} else {
pcap_close(pcap_g.pcap_handle);
ptv->cb_result = TM_ECODE_OK;
while (1) {
- if (suricata_ctl_flags & (SURICATA_STOP | SURICATA_KILL)) {
+ if (suricata_ctl_flags & SURICATA_STOP) {
SCReturnInt(TM_ECODE_OK);
}
}
while(1) {
- if (suricata_ctl_flags & (SURICATA_STOP | SURICATA_KILL)) {
+ if (suricata_ctl_flags & SURICATA_STOP) {
SCReturnInt(TM_ECODE_OK);
}
last_dump = p->ts.tv_sec;
}
} else if (unlikely(r == 0)) {
- if (suricata_ctl_flags & (SURICATA_STOP | SURICATA_KILL)) {
+ if (suricata_ctl_flags & SURICATA_STOP) {
SCReturnInt(TM_ECODE_OK);
}
CreateLowercaseTable();
}
-/* XXX hack: make sure threads can stop the engine by calling this
- function. Purpose: pcap file mode needs to be able to tell the
- engine the file eof is reached. */
+/** \brief make sure threads can stop the engine by calling this
+ * function. Purpose: pcap file mode needs to be able to tell the
+ * engine the file eof is reached. */
void EngineStop(void)
{
suricata_ctl_flags |= SURICATA_STOP;
}
-void EngineKill(void)
-{
- suricata_ctl_flags |= SURICATA_KILL;
-}
-
/**
* \brief Used to indicate that the current task is done.
*
int engine_retval = EXIT_SUCCESS;
while(1) {
- if (sigterm_count) {
- suricata_ctl_flags |= SURICATA_KILL;
- } else if (sigint_count) {
+ if (sigterm_count || sigint_count) {
suricata_ctl_flags |= SURICATA_STOP;
}
- if (suricata_ctl_flags & (SURICATA_KILL | SURICATA_STOP)) {
+ if (suricata_ctl_flags & SURICATA_STOP) {
SCLogNotice("Signal Received. Stopping engine.");
break;
}
/* runtime engine control flags */
#define SURICATA_STOP (1 << 0) /**< gracefully stop the engine: process all
outstanding packets first */
-#define SURICATA_KILL (1 << 1) /**< shut down asap, discarding outstanding
- packets. */
#define SURICATA_DONE (1 << 2) /**< packets capture ended */
/* Engine stage/status*/
#define u8_tolower(c) tolower((uint8_t)(c))
void EngineStop(void);
-void EngineKill(void);
void EngineDone(void);
int RunmodeIsUnittests(void);
" PktAcqLoop=%p, tmqh_in=%p,"
" tmqh_out=%p",
s, s ? s->PktAcqLoop : NULL, tv->tmqh_in, tv->tmqh_out);
- EngineKill();
-
TmThreadsSetFlag(tv, THV_CLOSED | THV_RUNNING_DONE);
pthread_exit((void *) -1);
return NULL;
TmThreadsSetFlag(tv, THV_CLOSED | THV_INIT_DONE | THV_RUNNING_DONE);
goto error;
} else {
- EngineKill();
TmThreadsSetFlag(tv, THV_CLOSED | THV_RUNNING_DONE);
goto error;
}
r = s->PktAcqLoop(tv, SC_ATOMIC_GET(s->slot_data), s);
- if (r == TM_ECODE_FAILED || TmThreadsCheckFlag(tv, THV_KILL_PKTACQ)
- || suricata_ctl_flags) {
+ if (r == TM_ECODE_FAILED) {
+ TmThreadsSetFlag(tv, THV_FAILED);
+ run = 0;
+ }
+ if (TmThreadsCheckFlag(tv, THV_KILL_PKTACQ) || suricata_ctl_flags) {
run = 0;
}
if (r == TM_ECODE_DONE) {
" PktAcqLoop=%p, tmqh_in=%p,"
" tmqh_out=%p",
s, s ? s->PktAcqLoop : NULL, tv->tmqh_in, tv->tmqh_out);
- EngineKill();
-
TmThreadsSetFlag(tv, THV_CLOSED | THV_RUNNING_DONE);
return NULL;
}
TmThreadsSetFlag(tv, THV_CLOSED | THV_INIT_DONE | THV_RUNNING_DONE);
goto error;
} else {
- EngineKill();
TmThreadsSetFlag(tv, THV_CLOSED | THV_RUNNING_DONE);
goto error;
}
r = s->PktAcqLoop(tv, SC_ATOMIC_GET(s->slot_data), s);
- if (r == TM_ECODE_FAILED || TmThreadsCheckFlag(tv, THV_KILL_PKTACQ)
- || suricata_ctl_flags) {
+ if (r == TM_ECODE_FAILED) {
+ TmThreadsSetFlag(tv, THV_FAILED);
+ run = 0;
+ }
+ if (TmThreadsCheckFlag(tv, THV_KILL_PKTACQ) || suricata_ctl_flags) {
run = 0;
}
if (r == TM_ECODE_DONE) {
/* check if we are setup properly */
if (s == NULL || tv->tmqh_in == NULL || tv->tmqh_out == NULL) {
- EngineKill();
-
TmThreadsSetFlag(tv, THV_CLOSED | THV_RUNNING_DONE);
pthread_exit((void *) -1);
return NULL;
void *slot_data = NULL;
r = s->SlotThreadInit(tv, s->slot_initdata, &slot_data);
if (r != TM_ECODE_OK) {
- EngineKill();
-
TmThreadsSetFlag(tv, THV_CLOSED | THV_RUNNING_DONE);
goto error;
}
void *slot_data = NULL;
r = s->SlotThreadInit(tv, s->slot_initdata, &slot_data);
if (r != TM_ECODE_OK) {
- EngineKill();
-
TmThreadsSetFlag(tv, THV_CLOSED | THV_RUNNING_DONE);
pthread_exit((void *) -1);
return NULL;
return 0;
}
- if (suricata_ctl_flags & (SURICATA_STOP | SURICATA_KILL)) {
+ if (suricata_ctl_flags & SURICATA_STOP) {
TAILQ_FOREACH_SAFE(uclient, &this->clients, next, tclient) {
UnixCommandClose(this, uclient->fd);
}