From: Cristian Rodríguez Date: Sun, 15 Jan 2023 01:33:13 +0000 (+0000) Subject: last: should not use errx/warnx on signal handlers X-Git-Tag: v2.39-rc1~123^2~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=05bd23aade3a975826a933ee3b9fc2ad92d0a9c3;p=thirdparty%2Futil-linux.git 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. --- diff --git a/login-utils/last.c b/login-utils/last.c index 84629278e5..cc73d5840f 100644 --- a/login-utils/last.c +++ b/login-utils/last.c @@ -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