last: should not use errx/warnx on signal handlers
err/warn/et all are not async signal safe because they call printf-like library functions that are never as-safe. ctime_r is also not as-safe. you cannot use static storage in the wrapper either, since access to it is not atomic.
This commit is contained in:
parent
3649a3db01
commit
05bd23aade
1 changed files with 4 additions and 14 deletions
|
@ -266,24 +266,14 @@ static int uread(FILE *fp, struct utmpx *u, int *quit, const char *filename)
|
|||
}
|
||||
|
||||
#ifndef FUZZ_TARGET
|
||||
/*
|
||||
* Print a short date.
|
||||
*/
|
||||
static char *showdate(void)
|
||||
{
|
||||
static char s[CTIME_BUFSIZ];
|
||||
|
||||
ctime_r(&lastdate, s);
|
||||
s[16] = 0;
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* SIGINT handler
|
||||
*/
|
||||
static void int_handler(int sig __attribute__((unused)))
|
||||
{
|
||||
errx(EXIT_FAILURE, _("Interrupted %s"), showdate());
|
||||
/* can't use err on signal handler */
|
||||
write(STDERR_FILENO, "Interrupted\n", sizeof("Interrupted\n")-1);
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -291,7 +281,7 @@ static void int_handler(int sig __attribute__((unused)))
|
|||
*/
|
||||
static void quit_handler(int sig __attribute__((unused)))
|
||||
{
|
||||
warnx(_("Interrupted %s"), showdate());
|
||||
write(STDERR_FILENO, "Interrupted\n", sizeof("Interrupted\n")-1);
|
||||
signal(SIGQUIT, quit_handler);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue