dcavalca / rpms / systemd

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