Detect signal sender (linux, ptrace)

Can I distinguish between a signal that is delivered directly to the process and delivered through the debugger.

Case 1:

 $ ./process1
 process1 (not ptraced)
 //set up handler
 alarm(5);
 ....
 //signal is handled and I can parse handler parameters

Case 2:

 $ debugger1 ./process1
 process1 (is ptraced by debugger1)
 //set up handler
 alarm(5);
 ...
 //signal is catched by debugger1. It resumes process1 with PTRACE_CONT,
 // signal_number is 4th parameter of PTRACE_CONT.
 //signal is redelivered to process1
 //and then is handled.

So, how can I detect in the signal handler whether it was re-sent by the debugger or sent by the system?

Linux OS, kernel 2.6.30. Programs are written in regular C. In a real program, SIGALRM is used, but it is generated not with alarm(), but with setitimer().

+3
source share
1 answer

man ptrace: ( http://linux.die.net/man/2/ptrace )

PTRACE_GETSIGINFO ( Linux 2.3.99-pre6) , . siginfo_t (. sigaction (2)) . (addr .)

PTRACE_SETSIGINFO ( Linux 2.3.99-pre6) . siginfo_t . . , ptrace() . (addr .)

PTRACE_CONT . SIGSTOP, , ; . , , , . (addr .)

+2

Source: https://habr.com/ru/post/1739001/


All Articles