reset sigaction to default

岁酱吖の 提交于 2021-01-05 04:59:21

问题


In Android the bionic loader sets a default signal handler for every process on statrtup:

void debugger_init()
{
    struct sigaction act;
    memset(&act, 0, sizeof(act));
    act.sa_sigaction = debugger_signal_handler;
    act.sa_flags = SA_RESTART | SA_SIGINFO;
    sigemptyset(&act.sa_mask);

    sigaction(SIGILL, &act, NULL);
    sigaction(SIGABRT, &act, NULL);
    sigaction(SIGBUS, &act, NULL);
    sigaction(SIGFPE, &act, NULL);
    sigaction(SIGSEGV, &act, NULL);
    sigaction(SIGSTKFLT, &act, NULL);
    sigaction(SIGPIPE, &act, NULL);
}

I would like to set it back to its default, meaning I want to ignore these signal and that the default handler will take place (CORE DUMP)

How do I revert the action performed ? I want to ignore all these as if the above function never was called


回答1:


Read signal(7), sigaction(2) and perhaps signal(2).

You could call

signal(SIGILL, SIG_DFL);
signal(SIGABRT, SIG_DFL);

and so on early in your main (which is entered after dynamic loading)

You could also use sigaction with sa_handler set to SIG_DFL

Of course, things are more tricky if you want to default handle these signals before your main, e.g. in some static constructor!




回答2:


I found it could lead unexpected behavior when mixed using sigaction and signal to set for one process.



来源:https://stackoverflow.com/questions/24803368/reset-sigaction-to-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!