Blame SOURCES/0057-mesg-use-only-stat-to-get-the-current-terminal-statu.patch

a0f4b9
From 7ad815523618c2a053d28061054a44ae9108ceb0 Mon Sep 17 00:00:00 2001
a0f4b9
From: Karel Zak <kzak@redhat.com>
a0f4b9
Date: Mon, 12 Apr 2021 09:39:59 +0200
a0f4b9
Subject: [PATCH 57/63] mesg: use only stat() to get the current terminal
a0f4b9
 status
a0f4b9
a0f4b9
open()+stat() does not work for example after su(1) (from root to
a0f4b9
non-root). It seems better to use only stat() to get the current
a0f4b9
terminal status.
a0f4b9
a0f4b9
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1906157
a0f4b9
Upstream: http://github.com/karelzak/util-linux/commit/c0246ce059503bbc078122a50d564ca36a66f348
a0f4b9
Signed-off-by: Karel Zak <kzak@redhat.com>
a0f4b9
---
a0f4b9
 term-utils/mesg.c | 12 +++++++-----
a0f4b9
 1 file changed, 7 insertions(+), 5 deletions(-)
a0f4b9
a0f4b9
diff --git a/term-utils/mesg.c b/term-utils/mesg.c
a0f4b9
index 8714ad1aa..21a4a8581 100644
a0f4b9
--- a/term-utils/mesg.c
a0f4b9
+++ b/term-utils/mesg.c
a0f4b9
@@ -123,13 +123,10 @@ int main(int argc, char *argv[])
a0f4b9
 
a0f4b9
 	if ((tty = ttyname(STDERR_FILENO)) == NULL)
a0f4b9
 		err(MESG_EXIT_FAILURE, _("ttyname failed"));
a0f4b9
-	if ((fd = open(tty, O_RDONLY)) < 0)
a0f4b9
-		err(MESG_EXIT_FAILURE, _("cannot open %s"), tty);
a0f4b9
-	if (fstat(fd, &sb))
a0f4b9
-		err(MESG_EXIT_FAILURE, _("stat of %s failed"), tty);
a0f4b9
 
a0f4b9
 	if (!*argv) {
a0f4b9
-		close(fd);
a0f4b9
+		if (stat(tty, &sb))
a0f4b9
+			err(MESG_EXIT_FAILURE, _("stat of %s failed"), tty);
a0f4b9
 		if (sb.st_mode & (S_IWGRP | S_IWOTH)) {
a0f4b9
 			puts(_("is y"));
a0f4b9
 			return IS_ALLOWED;
a0f4b9
@@ -138,6 +135,11 @@ int main(int argc, char *argv[])
a0f4b9
 		return IS_NOT_ALLOWED;
a0f4b9
 	}
a0f4b9
 
a0f4b9
+	if ((fd = open(tty, O_RDONLY)) < 0)
a0f4b9
+		err(MESG_EXIT_FAILURE, _("cannot open %s"), tty);
a0f4b9
+	if (fstat(fd, &sb))
a0f4b9
+		err(MESG_EXIT_FAILURE, _("stat of %s failed"), tty);
a0f4b9
+
a0f4b9
 	switch (rpmatch(argv[0])) {
a0f4b9
 	case RPMATCH_YES:
a0f4b9
 #ifdef USE_TTY_GROUP
a0f4b9
-- 
a0f4b9
2.31.1
a0f4b9