I have the following sigaction
handler function
void signal_term_handler(int sig)
{
printf("EXIT :TERM signal Received!\n");
int rc = flock(pid_file, LOCK_UN | LOCK_NB);
if(rc) {
char *piderr = "PID file unlock failed!";
fprintf(stderr, "%s\n", piderr);
printf(piderr);
}
abort();
}
Someone told me that flock
and printf
aren't async-signal-safe. And I could not find an alternate async-signal-safe function for flock
in this list.
and according to the above link:
when a signal interrupts an unsafe function and the signal-catching function calls an unsafe function, the behavior is undefined
Is there a way to make flock
async-signal-safe? Or is there another solution to execute flock
when I receive TERM
signal?
printf
, #16979559 forflock
. – Georgetta