...
If the request to register a signal handler can be honored, the signal()
function returns the value of the signal handler for the most recent successful call to the signal()
function for the specified signal. Otherwise, a value of
SIG_ERR
is returned and a positive value is stored in errno
.
Code Block | ||
---|---|---|
| ||
#include <signal.h> #include <stdlib.h> #include <string.h> typedef void (*pfv)(int); void handler(int signum) { pfv old_handler = signal(signum, handler); if (old_handler == SIG_ERR) { perror("SIGINT handler"); /* undefined behavior */ /* handle error condition */ } strcpy(err_msg, "SIGINT encountered."); } int main(void) { pfv old_handler = signal(SIGINT, handler); if (old_handler == SIG_ERR) { perror("SIGINT handler"); /* handle error condition */ } /* main code loop */ return 0; } |
The call to perror()
from handler()
also violates SIG30-C. Call only asynchronous-safe functions within signal handlers.
...