From 118ebe4b648692fb4112506a2c60bd4f1581b985 Mon Sep 17 00:00:00 2001 From: lnlan Date: Tue, 18 May 2021 22:15:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20sigaction=E5=BD=93=E5=89=8D=E7=9A=84sa?= =?UTF-8?q?=5Fmask=E7=9A=84=E8=AE=BE=E7=BD=AE=E6=96=B9=E6=B3=95=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E7=AC=A6=E5=90=88=E8=AF=A5=E6=8E=A5=E5=8F=A3=E8=AF=A5?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E7=9A=84=E8=AE=BE=E7=BD=AE=E6=9C=AC=E6=84=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【背景】 sigaction参数sa_mask的设置方法不符合设置本意,某种情况下会导致进程屏蔽字被覆盖 【修改方案】 修改设置方法,在handle处理前设置屏蔽字,处理后恢复屏蔽字 【影响】 如果用户在handle中设置了屏蔽字,该屏蔽字会在handle结束时会被覆盖掉。已测试了所有 相关用例,均可通过。待在linux验证确认是问题后修复。 re #I3QQA9 Signed-off-by: lnlanc Change-Id: Ibc55b1c8720463c8ff68c22fbcb376d8d15bc1e4 --- src/signal/sigaction.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/signal/sigaction.c b/src/signal/sigaction.c index 9cce43d7..45e1cebd 100755 --- a/src/signal/sigaction.c +++ b/src/signal/sigaction.c @@ -173,29 +173,26 @@ static int __sig_cannot_catche(int sig, sa_sighandler_t handler) static void __sig_operation(unsigned int receivedSigno) { int i; + sigset_t mask, oldmask; + + sigemptyset(&mask); + sigemptyset(&oldmask); for (i = 0; i < sizeof(sig_default_action) / sizeof(struct sig_default_act); i++) { if (!g_sig_arr[i].ign_flag && g_sig_arr[i].signo == receivedSigno && g_sig_arr[i].act.sa_handler) { + sigaddset(&mask, receivedSigno); + sigprocmask(SIG_BLOCK, &mask, &oldmask); + sigprocmask(SIG_BLOCK, &g_sig_arr[i].act.sa_mask, NULL); (*g_sig_arr[i].act.sa_handler)(g_sig_arr[i].signo); + sigprocmask(SIG_SETMASK, &oldmask, NULL); + return; } } } void arm_signal_process(unsigned int receivedSig) { - sigset_t mask, oldmask; - - sigemptyset(&mask); - sigemptyset(&oldmask); - - sigaddset(&mask, receivedSig); - sigprocmask(SIG_BLOCK, &mask, NULL); - __sig_operation(receivedSig); - - sigprocmask(SIG_BLOCK, NULL, &oldmask); - sigdelset(&oldmask, receivedSig); - sigprocmask(SIG_SETMASK, &oldmask, NULL); } static void __sig_add_def_action() @@ -267,7 +264,7 @@ static int __sig_action_opr(int sig, const sigaction_t *act, sigaction_t *oact) sigact->act.sa_mask = act->sa_mask; sigact->act.sa_flags = act->sa_flags; } - sigprocmask(SIG_BLOCK, &act->sa_mask, NULL); + pthread_spin_unlock(&sig_lite_lock); return ret; } -- GitLab