2aacef
From 7c2898cac4e05e24b24743e5d7d738f437d1e6f8 Mon Sep 17 00:00:00 2001
2aacef
From: Lennart Poettering <lennart@poettering.net>
2aacef
Date: Tue, 22 Nov 2022 12:56:38 +0100
2aacef
Subject: [PATCH] utmp-wtmp: fix error in case isatty() fails
2aacef
2aacef
(cherry picked from commit 80b780ba178a84b248ecee47eef82358480c9492)
2aacef
2aacef
Related: #2137584
2aacef
---
2aacef
 src/shared/utmp-wtmp.c | 4 +++-
2aacef
 1 file changed, 3 insertions(+), 1 deletion(-)
2aacef
2aacef
diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c
2aacef
index d2c8473c60..20add0e81b 100644
2aacef
--- a/src/shared/utmp-wtmp.c
2aacef
+++ b/src/shared/utmp-wtmp.c
2aacef
@@ -292,8 +292,10 @@ static int write_to_terminal(const char *tty, const char *message) {
2aacef
         assert(message);
2aacef
 
2aacef
         fd = open(tty, O_WRONLY|O_NONBLOCK|O_NOCTTY|O_CLOEXEC);
2aacef
-        if (fd < 0 || !isatty(fd))
2aacef
+        if (fd < 0)
2aacef
                 return -errno;
2aacef
+        if (!isatty(fd))
2aacef
+                return -ENOTTY;
2aacef
 
2aacef
         p = message;
2aacef
         left = strlen(message);