summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2024-08-27 19:37:00 +0800
committerluwenpeng <[email protected]>2024-08-27 19:37:00 +0800
commit7e04992aa07a08fc2f4f34ca7b6cb3da34fff6fc (patch)
treef376845422ef1576e6e6846813eadd47c13aafe6
parent79e70f71457aebc58c157dda09cb8656f8cdde5e (diff)
SIGINT for force exit, SIGSTOP for graceful exit
-rw-r--r--src/core/main.cpp15
-rw-r--r--src/core/stellar_core.cpp23
-rw-r--r--src/packet_io/dumpfile_io.cpp4
3 files changed, 16 insertions, 26 deletions
diff --git a/src/core/main.cpp b/src/core/main.cpp
index 1e5fb81..84b9ec4 100644
--- a/src/core/main.cpp
+++ b/src/core/main.cpp
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stddef.h>
#include <signal.h>
+#include <stdlib.h>
#include "stellar/log.h"
#include "stellar/stellar.h"
@@ -13,19 +14,13 @@ static void signal_handler(int signo)
if (signo == SIGINT)
{
- STELLAR_LOG_FATAL(logger, "signal", "SIGINT received, notify threads to exit");
- stellar_loopbreak(st);
- }
-
- if (signo == SIGQUIT)
- {
- STELLAR_LOG_FATAL(logger, "signal", "SIGQUIT received, notify threads to exit");
- stellar_loopbreak(st);
+ STELLAR_LOG_FATAL(logger, "signal", "SIGINT received, force exit");
+ exit(0);
}
- if (signo == SIGTERM)
+ if (signo == SIGSTOP)
{
- STELLAR_LOG_FATAL(logger, "signal", "SIGTERM received, notify threads to exit");
+ STELLAR_LOG_FATAL(logger, "signal", "SIGSTOP received, notify threads graceful exit");
stellar_loopbreak(st);
}
diff --git a/src/core/stellar_core.cpp b/src/core/stellar_core.cpp
index ac18870..992a45c 100644
--- a/src/core/stellar_core.cpp
+++ b/src/core/stellar_core.cpp
@@ -42,7 +42,6 @@ struct stellar_thread
pthread_t tid;
uint16_t idx;
uint64_t is_runing;
- uint64_t need_exit;
uint64_t last_free_expired_session_timestamp;
uint64_t last_free_expired_ip_frag_timestamp;
uint64_t last_merge_thread_stat_timestamp;
@@ -227,7 +226,7 @@ static void *work_thread(void *arg)
ATOMIC_SET(&thread->is_runing, 1);
CORE_LOG_FATAL("worker thread %d runing", thr_idx);
- while (ATOMIC_READ(&thread->need_exit) == 0)
+ while (ATOMIC_READ(&runtime->need_exit) == 0)
{
/*
* We use the system's real time instead of monotonic time for the following reasons:
@@ -366,13 +365,15 @@ static void *work_thread(void *arg)
}
}
- if (froce_session_expire_before_exit)
+ while (sess_stat->tcp_sess_used > 0 || sess_stat->udp_sess_used > 0)
{
- free_expired_sessions(sess_mgr, UINT64_MAX, UINT64_MAX);
- }
- else
- {
- while (sess_stat->tcp_sess_used > 0 || sess_stat->udp_sess_used > 0)
+ // froce session expire
+ if (froce_session_expire_before_exit)
+ {
+ free_expired_sessions(sess_mgr, free_expired_session_batch, UINT64_MAX);
+ }
+ // wait session expire
+ else
{
now_ms = clock_get_real_time_ms();
free_expired_sessions(sess_mgr, free_expired_session_batch, now_ms);
@@ -605,11 +606,7 @@ void stellar_run(struct stellar *st)
// only available in dumpfile mode
if (packet_io_isbreak(runtime->packet_io))
{
- for (uint16_t i = 0; i < config->pkt_io_opts.nr_threads; i++)
- {
- struct stellar_thread *thread = &runtime->threads[i];
- ATOMIC_SET(&thread->need_exit, 1);
- }
+ ATOMIC_SET(&runtime->need_exit, 1);
CORE_LOG_FATAL("notify worker thread to exit");
stellar_stat_output(runtime->stat); // flush stat
break;
diff --git a/src/packet_io/dumpfile_io.cpp b/src/packet_io/dumpfile_io.cpp
index 138ff3f..005ce7f 100644
--- a/src/packet_io/dumpfile_io.cpp
+++ b/src/packet_io/dumpfile_io.cpp
@@ -277,7 +277,7 @@ erro_out:
usleep(1000); // 1ms
}
- PACKET_IO_LOG_FATAL("dumpfile io thread exit");
+ PACKET_IO_LOG_FATAL("dumpfile io thread exit (read_pcap_files: %lu, read_pcap_pkts: %lu)", handle->read_pcap_files, ATOMIC_READ(&handle->read_pcap_pkts));
ATOMIC_SET(&handle->io_thread_is_runing, 0);
return NULL;
@@ -335,8 +335,6 @@ void dumpfile_io_free(struct dumpfile_io *handle)
usleep(1000);
}
- PACKET_IO_LOG_FATAL("dumpfile io thread read pcap files %lu, read pcap pkts %lu", handle->read_pcap_files, ATOMIC_READ(&handle->read_pcap_pkts));
-
struct pcap_pkt *pcap_pkt = NULL;
for (uint16_t i = 0; i < handle->nr_threads; i++)
{