Вопрос

I have a library which installs a signal handler for SIGSEGV for debugging purpose. The SIGSEGV handler just prints some information and then exits the program.

Recently, I had the need to invoke this library from Java (using JNI), and the problem I ran into is that JVM also installs a signal handler for SIGSEGV for more useful purpose than mine.

So the action what I want to choose is that in case my library finds a signal handler already installed for a signal, it simply doesn't install any signal.

For clarity, I am using sigaction call.

Now to achieve my functionality what I have to do is:

a. BLOCK all signals.

b. call sigaction and check if oact returns a valid handler.

c. if it does, re-call sigaction with oact as new act.

d. UNBLOCK signals.

B and c seem to be cumbersome to me. What I want is to be able to just determine if a particular signal already has a handler without first replacing the handler and then re-replacing it with the original handler (achieving nothing).

Is there anything more granular than sigaction?

Это было полезно?

Решение

You can call sigaction(SIGSEGV, NULL, &sa) to query the signal disposition without altering it.

Note that blocking signals does not "lock out" other threads because signal masks are per thread while signal dispositions are common for all threads in a process.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top