SIGINT for force exit, SIGSTOP for graceful exit

This commit is contained in:
luwenpeng
2024-08-27 19:37:00 +08:00
parent 79e70f7145
commit 7e04992aa0
3 changed files with 16 additions and 26 deletions

View File

@@ -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);
STELLAR_LOG_FATAL(logger, "signal", "SIGINT received, force exit");
exit(0);
}
if (signo == SIGQUIT)
if (signo == SIGSTOP)
{
STELLAR_LOG_FATAL(logger, "signal", "SIGQUIT received, notify threads to exit");
stellar_loopbreak(st);
}
if (signo == SIGTERM)
{
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);
}

View File

@@ -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)
}
}
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, UINT64_MAX, UINT64_MAX);
free_expired_sessions(sess_mgr, free_expired_session_batch, UINT64_MAX);
}
// wait session expire
else
{
while (sess_stat->tcp_sess_used > 0 || sess_stat->udp_sess_used > 0)
{
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;

View File

@@ -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++)
{