提交 5db71f03 编写于 作者: D dhy308

Fix review issues.

Issue: I6AEEI
Test: Build & Boot Devices
Signed-off-by: Ndhy308 <tony.gan@huawei.com>
上级 fb686cb6
......@@ -16,17 +16,17 @@
#define SIGCHAIN_TEST_SET_MASK(set, fun, signo, num) do{ \
int result = sigemptyset(&set); \
if (result != 0) { \
EXPECT_FALSE(fun, (result == 0)); \
EXPECT_FALSE(fun, true); \
} \
for (int i = 0; i < num; i++) { \
result = sigaddset(&set, signo[i]); \
if (result != 0) { \
EXPECT_FALSE(fun, (result == 0)); \
EXPECT_FALSE(fun, true); \
} \
} \
result = sigprocmask(SIG_BLOCK, &set, NULL); \
if (result != 0) { \
EXPECT_FALSE(fun, (result == 0)); \
EXPECT_FALSE(fun, true); \
} \
} while (0)
......
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <signal.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
/**
* @brief the special handler
*/
static void signal_handler1(int signo)
{
EXPECT_EQ("sigchain_intercept_sigaction_001", signo, SIGHUP);
sigset_t set = {0};
int signal[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGSEGV, SIGHUP};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigaction_002", signal, SIGCHIAN_TEST_SIGNAL_NUM_2);
raise(SIGSEGV);
}
/**
* @brief the special handler
*/
static void signal_handler2(int signo)
{
EXPECT_EQ("sigchain_intercept_sigaction_001", signo, SIGSEGV);
}
/**
* @tc.name : sigchain_intercept_sigaction_004
* @tc.desc : Test the influence of sigchain on sigaction, the signals are not registered with
* the special handler, and mask and rasie the signal at the special handler
* @tc.level : Level 0
*/
static void sigchain_intercept_sigaction_004()
{
struct sigaction siga1 = {
.sa_handler = signal_handler1,
};
sigaction(SIGHUP, &siga1, NULL);
struct sigaction siga2 = {
.sa_handler = signal_handler2,
};
sigaction(SIGSEGV, &siga2, NULL);
}
int main(void)
{
sigchain_intercept_sigaction_004();
raise(SIGHUP);
return t_status;
}
\ No newline at end of file
......@@ -32,6 +32,7 @@ static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *uconte
sigset_t set = {0};
int signal[SIGCHIAN_TEST_SIGNAL_NUM_2] = {SIGHUP, SIGSEGV};
SIGCHAIN_TEST_SET_MASK(set, "sigchain_intercept_sigprocmask_001", signal, SIGCHIAN_TEST_SIGNAL_NUM_2);
raise(SIGSEGV);
g_count++;
}
return false;
......@@ -43,6 +44,7 @@ static bool sigchain_special_handler(int signo, siginfo_t *siginfo, void *uconte
static bool sigchain_special_handler1(int signo, siginfo_t *siginfo, void *ucontext_raw)
{
EXPECT_EQ("sigchain_intercept_sigprocmask_005", signo, SIGSEGV);
EXPECT_EQ("sigchain_intercept_sigprocmask_005", g_count, 1);
return false;
}
......@@ -59,7 +61,7 @@ static void signal_handler(int signo)
/**
* @tc.name : sigchain_intercept_sigprocmask_005
* @tc.desc : Test the influence of sigchain on sigprocmask, the signals are registered with
* the special handler
* the special handler, and mask and rasie the signal at the special handler
* @tc.level : Level 0
*/
static void sigchain_intercept_sigprocmask_005()
......@@ -97,7 +99,5 @@ int main(void)
{
sigchain_intercept_sigprocmask_005();
raise(SIGHUP);
raise(SIGSEGV);
raise(SIGHUP);
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <signal.h>
#include <wchar.h>
#include <stdlib.h>
#include "test.h"
#include "functionalext.h"
#include "sigchain_util.h"
/**
* @tc.name : sigchain_intercept_sigprocmask_006
* @tc.desc : Test the influence of sigchain on sigprocmask, the new set is null.
* @tc.level : Level 0
*/
static void sigchain_intercept_sigprocmask_006()
{
int result = sigprocmask(SIG_BLOCK, NULL, NULL);
if (result != 0) {
EXPECT_FALSE("sigchain_intercept_sigprocmask_006", true);
}
}
int main(void)
{
sigchain_intercept_sigprocmask_006();
return t_status;
}
\ No newline at end of file
......@@ -38,6 +38,7 @@ functionalext_sigchain_list = [
"sigchain_intercept_sigaction_a",
"sigchain_intercept_sigaction_b",
"sigchain_intercept_sigaction_c",
"sigchain_intercept_sigaction_d",
"sigchain_intercept_signal_a",
"sigchain_intercept_signal_b",
"sigchain_intercept_signal_c",
......@@ -46,5 +47,6 @@ functionalext_sigchain_list = [
"sigchain_intercept_sigprocmask_c",
"sigchain_intercept_sigprocmask_d",
"sigchain_intercept_sigprocmask_e",
"sigchain_intercept_sigprocmask_f",
"sigchain_call_special_handler_a",
]
......@@ -6,10 +6,15 @@ extern void intercept_sigprocmask(int how, sigset_t *restrict set);
int sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old)
{
sigset_t tmpset = *set;
intercept_sigprocmask(how, &tmpset);
const sigset_t *new_set_ptr = &tmpset;
int r = pthread_sigmask(how, new_set_ptr, old);
int r = 0;
if (set) {
sigset_t tmpset = *set;
intercept_sigprocmask(how, &tmpset);
const sigset_t *new_set_ptr = &tmpset;
r = pthread_sigmask(how, new_set_ptr, old);
} else {
r = pthread_sigmask(how, set, old);
}
if (!r) return r;
errno = r;
return -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册