0

I'm writing a library where I fork() and execvp() to start another program. As I've understood, execvX() resets "custom" signal handlers to SIG_DFL but it doesn't set any ignored signals handlers to SIG_DFL.

Keeping in mind it is a library and I can't control what users will do with the signals, is it a good idea to set the signal handlers of ignored signals to SIG_DFL?

If it is, is there some way to set all signal handlers to SIG_DFL at once? Do I have to iterate through all signals numbers instead? And in this case, how can I find the last possible signal number? I've seen there is _NSIG in bits/signum.h. Is this constant part of POSIX or is it Linux-specific?

Thanks.

Víctor Fernández
  • 1,754
  • 1
  • 16
  • 15

1 Answers1

1

According to execve(2) man page,

The dispositions of any signals that are being caught are reset to the default (signal(7)).

The signal(7) man page adds:

During an execve(2), the dispositions of handled signals are reset to the default; the dispositions of ignored signals are left unchanged.

So you need to reset one by one the signals you want to ignore or default before your execve

And I see an NSIG constant in /usr/include/signal.h

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547