d1a424c002
This will allow us to redefine the exit function.
For example:
```
#define exit(code) { \
fprintf(stderr, "%s:%d: exit(%s) in function ‘%s’\n",
__FILE__, __LINE__, #code, __func__); \
_exit(code); \
}
```
26 lines
492 B
C
26 lines
492 B
C
#include <signal.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
|
|
void handler(int sig) {
|
|
puts("Signal handler called!");
|
|
}
|
|
|
|
int main(void) {
|
|
if (signal(SIGUSR1, &handler) == SIG_ERR) {
|
|
puts("Signal error!");
|
|
printf("%d\n", errno);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
puts("Raising...");
|
|
if (raise(SIGUSR1)) {
|
|
puts("Raise error!");
|
|
printf("%d\n", errno);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
puts("Raised.");
|
|
}
|