]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
last: should not use errx/warnx on signal handlers
authorCristian Rodríguez <crrodriguez@opensuse.org>
Sun, 15 Jan 2023 01:33:13 +0000 (01:33 +0000)
committerCristian Rodríguez <crrodriguez@opensuse.org>
Sun, 15 Jan 2023 01:33:13 +0000 (01:33 +0000)
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.

login-utils/last.c

index 84629278e5e4af613d8bbbbc32db85cd9648482b..cc73d5840f4032f05b772312cde84f2dd691b537 100644 (file)
@@ -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