gpt4 book ai didi

c - 如何在 sigset_t 中设置 sa_mask?

转载 作者:太空狗 更新时间:2023-10-29 15:11:38 27 4
gpt4 key购买 nike

海合会 (海湾合作委员会) 4.6.0 c89

我有一个这样声明的信号处理程序:

   /* Setup signal handler */
struct sigaction new_action;
new_action.sa_handler = g_signal_handler;
new_action.sa_flags = SA_ONSTACK;

if(sigaction(SIGINT, &new_action, NULL) == -1) {
fprintf(stderr, "Failed to setup signal handlers.");
return -1;
}

当我通过 valgrind 运行我的代码时,即 valgrind --leak-check=full 它发现了以下错误:

==5206== Syscall param rt_sigaction(act->sa_mask) points to uninitialised byte(s)
==5206== at 0x347A435455: __libc_sigaction (in /lib64/libc-2.14.so)

所以在查看手册页后我决定这样设置,只是为了测试:

new_action.sa_mask = SA_NODEFER;

但是,这只会给我以下错误:

error: incompatible types when assigning to type ‘__sigset_t’ from type ‘int’

非常感谢您的任何建议,

最佳答案

试试这个:

/* Signals blocked during the execution of the handler. */
sigemptyset(&new_action.sa_mask);
sigaddset(&new_action.sa_mask, SIGINT);

The sa_mask field allows us to specify a set of signals that aren’t permitted to interrupt execution of this handler. In addition, the signal that caused the handler to be invoked is automatically added to the process signal mask.

关于c - 如何在 sigset_t 中设置 sa_mask?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6965209/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com