1 Star 0 Fork 2

HoperunHarmony/stress-ng

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
stress-sigpending.c 3.04 KB
一键复制 编辑 原始数据 按行查看 历史
/*
* Copyright (C) 2013-2021 Canonical, Ltd.
* Copyright (C) 2022 Colin Ian King.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "stress-ng.h"
static const stress_help_t help[] = {
{ NULL, "sigpending N", "start N workers exercising sigpending" },
{ NULL, "sigpending-ops N", "stop after N sigpending bogo operations" },
{ NULL, NULL, NULL }
};
/*
* stress_usr1_handler()
* SIGUSR1 signal handler
*/
static void MLOCKED_TEXT stress_usr1_handler(int signum)
{
(void)signum;
}
/*
* stress_sigpending
* stress sigpending system call
*/
static int stress_sigpending(const stress_args_t *args)
{
sigset_t new_sigset, old_sigset;
if (stress_sighandler(args->name, SIGUSR1, stress_usr1_handler, NULL) < 0)
return EXIT_FAILURE;
stress_set_proc_state(args->name, STRESS_STATE_RUN);
do {
(void)sigemptyset(&new_sigset);
(void)sigaddset(&new_sigset, SIGUSR1);
if (sigprocmask(SIG_SETMASK, &new_sigset, NULL) < 0) {
pr_fail("%s: sigprocmask failed, errno=%d (%s)\n",
args->name, errno, strerror(errno));
return EXIT_FAILURE;
}
(void)kill(args->pid, SIGUSR1);
if (sigpending(&new_sigset) < 0) {
pr_fail("%s: sigpending failed, errno=%d (%s)\n",
args->name, errno, strerror(errno));
continue;
}
/* We should get a SIGUSR1 here */
if (!sigismember(&new_sigset, SIGUSR1)) {
pr_fail("%s: did not get a SIGUSR1 pending signal\n", args->name);
continue;
}
/* Unmask signal, signal is handled */
(void)sigemptyset(&new_sigset);
(void)sigprocmask(SIG_SETMASK, &new_sigset, NULL);
/* And it is no longer pending */
if (sigpending(&new_sigset) < 0) {
pr_fail("%s: got an unexpected SIGUSR1 pending signal\n", args->name);
continue;
}
if (sigismember(&new_sigset, SIGUSR1)) {
pr_fail("%s: got an unexpected SIGUSR1 signal\n", args->name);
continue;
}
/* Exercise invalid sigprocmask how argument */
(void)sigprocmask(~0, &new_sigset, NULL);
/* Fetch existing sigset */
(void)sigemptyset(&old_sigset);
(void)sigprocmask(SIG_SETMASK, NULL, &old_sigset);
/* Do nothing */
(void)sigprocmask(SIG_SETMASK, NULL, NULL);
inc_counter(args);
} while (keep_stressing(args));
stress_set_proc_state(args->name, STRESS_STATE_DEINIT);
return EXIT_SUCCESS;
}
stressor_info_t stress_sigpending_info = {
.stressor = stress_sigpending,
.class = CLASS_INTERRUPT | CLASS_OS,
.verify = VERIFY_ALWAYS,
.help = help
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hoperun_harmony/stress-ng.git
git@gitee.com:hoperun_harmony/stress-ng.git
hoperun_harmony
stress-ng
stress-ng
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385