]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mesg: do not print 'ttyname failed' message unless --verbose requested
authorSami Kerola <kerolasa@iki.fi>
Thu, 2 Aug 2018 18:35:51 +0000 (19:35 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 3 Aug 2018 10:27:02 +0000 (12:27 +0200)
Lots of people are confused why mesg(1) is priting this message.  Usual
cause seems to be an uninteractive shell trying to turn running 'mesg n'
from a /root/.profile where command invocation is by default on debian based
systems.  This might be rare case when failing silently is better.

[kzak@redhat.com: - add note to the man page
                  - fix if(isatty()) logic]

Reference: https://www.google.com/search?q=mesg+ttyname+failed
Review: https://marc.info/?l=util-linux-ng&m=153319988631233&w=2
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
term-utils/mesg.1
term-utils/mesg.c

index b7e73a5945a2923b7e5267fbe15b47ef9432e19b..15c834dd71e49a409d58627307c757e7ef03015a 100644 (file)
@@ -55,6 +55,15 @@ write access by default, at least for the primary login shell.  To make
 sure your ttys are set the way you want them to be set,
 .B mesg
 should be executed in your login scripts.
+.PP
+The
+.B mesg
+utility silently exits with error status 2 if the current standard error output does
+not refer to the terminal.  In this case execute
+.B mesg
+is pointless.  The command line option \fB\-\-verbose\fR forces
+mesg to print a warning in this situation.  This behaviour has been introduced
+in version 2.33.
 .SH ARGUMENTS
 .TP
 .B n
index 8714ad1aa38c400943c95c3dbe76be3a0746b682..608f3cf61ace1133f93fab3c6daca5ce9cd62ec8 100644 (file)
@@ -121,6 +121,11 @@ int main(int argc, char *argv[])
        argc -= optind;
        argv += optind;
 
+       if (!isatty(STDERR_FILENO)) {
+               if (verbose)
+                       warnx(_("no tty"));
+               exit(MESG_EXIT_FAILURE);
+       }
        if ((tty = ttyname(STDERR_FILENO)) == NULL)
                err(MESG_EXIT_FAILURE, _("ttyname failed"));
        if ((fd = open(tty, O_RDONLY)) < 0)