aboutsummaryrefslogtreecommitdiffstats
path: root/src/signal.cpp
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2022-01-09 20:28:37 +0000
committerSaturneric <[email protected]>2022-01-09 20:28:52 +0000
commitd52c544f0d97020a3ada0dddbf599c97906c0b90 (patch)
tree1168cc0a6140b4a7b8a4aef7ca18284a8f92eb6c /src/signal.cpp
parent<fixed>(ui): fix SIGSEGV when closing. (diff)
downloadGpgFrontend-d52c544f0d97020a3ada0dddbf599c97906c0b90.tar.gz
GpgFrontend-d52c544f0d97020a3ada0dddbf599c97906c0b90.zip
<feat ,fixed>(src): Optimize signal handlers and fix sequence errors during startup.
1. When the same signal is continuously received (three times in a row), the program exits to avoid falling into a loop. 2. The QCoreApplication should be exited after displaying the information.
Diffstat (limited to 'src/signal.cpp')
-rw-r--r--src/signal.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/signal.cpp b/src/signal.cpp
index efcd8146..c5b6727e 100644
--- a/src/signal.cpp
+++ b/src/signal.cpp
@@ -29,7 +29,20 @@
extern jmp_buf recover_env;
void handle_signal(int sig) {
- LOG(INFO) << "signal caught";
+ static int _repeat_handle_num = 1, last_sig = sig;
+ LOG(INFO) << "signal caught" << sig;
+
+ if (last_sig == sig)
+ _repeat_handle_num++;
+ else
+ _repeat_handle_num = 1, last_sig = sig;
+
+ if (_repeat_handle_num > 3) {
+ LOG(INFO) << "The same signal appears three times, execute the termination "
+ "operation. ";
+ exit(-1);
+ }
+
#ifndef WINDOWS
siglongjmp(recover_env, 1);
#else