From d9b705ab98e1f31c41340c9edc3c08068edddeea Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 14 Feb 2021 04:17:15 +0100 Subject: [PATCH] Runtime detection of working UTMP/WTMP support in system Signed-off-by: Joachim Wiberg --- src/util.c | 11 +++++++++++ src/util.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/util.c b/src/util.c index 331a5e5b..0679126a 100644 --- a/src/util.c +++ b/src/util.c @@ -30,6 +30,7 @@ #include #include #include +#include #include /* sysinfo() */ #include /* strlcat() */ #include "util.h" @@ -75,6 +76,16 @@ int echo(char *file, int append, char *fmt, ...) return 0; } +/* + * musl libc default to /dev/null/utmp and /dev/null/wtmp, respectively. + * See https://www.openwall.com/lists/musl/2012/03/04/4 for reasoning. + * Also, there's no __MUSL__, so we cannot make a libc-specific #ifdef + */ +int has_utmp(void) +{ + return strncmp(_PATH_UTMP, "/dev/null", 9); +} + int strtobytes(char *arg) { int mod = 0, bytes; diff --git a/src/util.h b/src/util.h index 1a46fa03..eb7aaa34 100644 --- a/src/util.h +++ b/src/util.h @@ -40,6 +40,7 @@ extern char *prognm; char *progname (char *arg0); int echo (char *file, int append, char *fmt, ...); +int has_utmp (void); int strtobytes (char *arg); void do_sleep (unsigned int sec);