2

我已经定义了 sigaction 并且它工作正常。但是,我想在我的操作完成后恢复原始信号。这是我的签名:

static void signal_handler(int signal, siginfo_t *info, void *reserved)
{
    //Some logging statements
    //How do I restore the original signal here??
}

信号处理程序是从 JNI_Onload 设置的:

extern "C" jint JNI_OnLoad(JavaVM* vm, void* /*reserved*/)
{
    struct sigaction handler, action_old;
    memset(&handler, 0, sizeof(handler));
    handler.sa_sigaction = signal_handler;
    handler.sa_flags = SA_SIGINFO;
    sigaction(SIGILL, &handler, &action_old);
    sigaction(SIGABRT, &handler, &action_old);
    sigaction(SIGBUS, &handler, &action_old);
    sigaction(SIGFPE, &handler, &action_old);
    sigaction(SIGSEGV, &handler, &action_old);
    sigaction(SIGSTKFLT, &handler, &action_old);

    //Can I restore prior signal here???

    return JNI_VERSION_1_6;
}
4

2 回答 2

2

将旧操作保存在全局(或文件范围)变量(或由信号 id 索引的数组)中,并sigaction从信号处理程序内部调用以恢复以前的行为。 sigaction保证是异步信号安全的。

另见: http: //pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04_03

于 2011-09-14T21:21:10.277 回答
0

http://www.gnu.org/s/hello/manual/libc/Basic-Signal-Handling.html - 说:

信号函数返回先前对指定符号有效的操作。您可以保存此值并稍后通过再次调用信号来恢复它。

于 2011-09-14T21:19:49.147 回答