0

int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
If act is non-NULL, the new action for signal signum is installed from act. If oldact is non-NULL, the previous action is saved in oldact.

This comes from https://linux.die.net/man/2/sigaction, I don't quite understand what "previous action" means. Does it means the action by default referred to the signum? I've tested the code as below but it gave me a core dumped:

#include <signal.h>
#include <unistd.h>    

struct sigaction act, oact;
void func(int p)
{
    oact.sa_handler(p);  # core dumped here
}

int main(int argc, char **argv)
{
    act.sa_handler = func;
    sigaction(SIGINT, &act, &oact);
    sleep(100);
    return 0;
}
Yves
  • 11,597
  • 17
  • 83
  • 180
  • The previous action need not be represented by a callable function pointer! – Kerrek SB Jun 07 '19 at 10:00
  • Related: [Explicitly invoke SIG_DFL/SIG_IGN handlers on Linux](https://stackoverflow.com/questions/3147840/explicitly-invoke-sig-dfl-sig-ign-handlers-on-linux) – Mark Plotnick Jun 07 '19 at 10:02

0 Answers0