Two question about signal handlers

F

Free Bird

Hello all,

I have two questions about signal handlers. First of all, is it possible to
specify a signal handler for all non-specified signals? Since ISO C defines
only six signals but POSIX defines a lot more of them, I'd like a way to
just use a generic signal handler (which just exits with a special exit
code, for instance) for all non-standard signals, but I have no idea if this
is possible while remaining ISO C compliant.

Secondly, can anyone with a copy of the C99 standard confirm that it's safe
to call _Exit() from signal handlers which may be called asynchronously?

Thanks in advance for answering.
 
A

Alan Balmer

Hello all,

I have two questions about signal handlers. First of all, is it possible to
specify a signal handler for all non-specified signals? Since ISO C defines
only six signals but POSIX defines a lot more of them, I'd like a way to
just use a generic signal handler (which just exits with a special exit
code, for instance) for all non-standard signals, but I have no idea if this
is possible while remaining ISO C compliant.

Secondly, can anyone with a copy of the C99 standard confirm that it's safe
to call _Exit() from signal handlers which may be called asynchronously?
Yes. It's specifically permitted. It will, of course, not execute any
atexit-registered functions or other signal handlers.
 
F

Free Bird

Alan said:
Yes. It's specifically permitted. It will, of course, not execute any
atexit-registered functions or other signal handlers.

Ah, thank you. I just needed to be sure of that. :)
 
F

Free Bird

Free said:
I have two questions about signal handlers. First of all, is it possible to
specify a signal handler for all non-specified signals? Since ISO C defines
only six signals but POSIX defines a lot more of them, I'd like a way to
just use a generic signal handler (which just exits with a special exit
code, for instance) for all non-standard signals, but I have no idea if this
is possible while remaining ISO C compliant.

I don't mean to sound impatient, but doesn't anyone have an answer to this
quesion? And yes, I know I made a mistake in the subject line (maybe that
caused you to think I had only one question ;)).

If I shouldn't have posted this reminder just yet I apologize.
 
S

Steven Kobes

Free said:
First of all, is it possible to specify a signal handler for all
non-specified signals?

I doubt it.
Secondly, can anyone with a copy of the C99 standard confirm that
it's safe to call _Exit() from signal handlers which may be called
asynchronously?

Does this help?

7.14.1.1 p5:

If the signal occurs other than as the result of calling the abort
or raise function, the behavior is undefined if the signal handler
refers to any object with static storage duration other than by
assigning a value to an object declared as volatile sig_atomic_t,
or the signal handler calls any function in the standard library
other than the abort function, the _Exit function, or the signal
function with the first argument equal to the signal number
corresponding to the signal that caused the invocation of the
handler. Furthermore, if such a call to the signal function
results in a SIG_ERR return, the value of errno is indeterminate.
 
F

Free Bird

Steven said:
Does this help?

7.14.1.1 p5:

If the signal occurs other than as the result of calling the abort
or raise function, the behavior is undefined if the signal handler
refers to any object with static storage duration other than by
assigning a value to an object declared as volatile sig_atomic_t,
or the signal handler calls any function in the standard library
other than the abort function, the _Exit function, or the signal
function with the first argument equal to the signal number
corresponding to the signal that caused the invocation of the
handler. Furthermore, if such a call to the signal function
results in a SIG_ERR return, the value of errno is indeterminate.

Ah, so that's the exact text. Thank you!
 
A

Alan Balmer

I don't mean to sound impatient, but doesn't anyone have an answer to this
quesion? And yes, I know I made a mistake in the subject line (maybe that
caused you to think I had only one question ;)).

If I shouldn't have posted this reminder just yet I apologize.
OK, I'll take a whack at it. There is no defined method of doing this.
There's nothing that I can see that would prevent you calling signal()
for the entire range of integers supported by the implementation, then
resetting the ones you want to be different, but I wouldn't recommend
it.

More sensibly, you could restrict to the range of actual signal values
for the implementation, but of course it wouldn't be portable.
 
F

Free Bird

Alan said:
OK, I'll take a whack at it. There is no defined method of doing this.
There's nothing that I can see that would prevent you calling signal()
for the entire range of integers supported by the implementation, then
resetting the ones you want to be different, but I wouldn't recommend
it.
Yes, that's one of the ideas I came up with, but I quickly rejected it. I
mean, I don't even want to think about how long this would take on a system
with 64-bit ints... I suppose I could call signal() for all values from 0 to
32767 and be reasonably certain I have covered all signals, but I was hoping
there would be a better way.
More sensibly, you could restrict to the range of actual signal values
for the implementation, but of course it wouldn't be portable.
Indeed.

Well, it seems there is indeed no way to do this in ISO C. That's
unfortunate, but I suppose I'll just have to live with it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top