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