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

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