Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the handlers' name/address for some signals (e.g. SIGINT) in Postgres?

How to get the handlers' name/address for some signals (e.g. SIGINT) in Postgres? We can use signal(SIGINT, my_handler) to set the signal handler, but is there a function that can tell us which function (in this case, my_handler) deals with some signal (in this case, SIGINT)? Or Could we find out using GDB?

like image 685
lil Avatar asked Feb 29 '12 07:02

lil


1 Answers

The function you are looking for is sigaction. It takes three arguments, the first is the signal, the second is a pointer to the new sigaction structure, and the third is a pointer to the old sigaction structure (to be populated by the function). To get the current signal handler, call the sigaction with the second argument set to NULL. For example,

struct sigaction oldact;
sigaction(SIGINT, NULL, &oldact);

printf("SIGINT handler address: 0x%lx\n", oldact.sa_sigaction);

This approach will require you to modify the source.

You may also be able to do this via gdb, which will not require modifying the source. For example, this will work if you attach to the process after it has registered signal handlers.

(gdb) call malloc(sizeof(struct sigaction))
(gdb) sigaction(SIGINT, NULL, $1)
(gdb) print ((struct sigaction *)$1)->sa_sigaction
(gdb) info sym <address from previous step>
like image 51
80x25 Avatar answered Nov 16 '22 04:11

80x25