diff --git a/term-utils/mesg.1 b/term-utils/mesg.1 index b7e73a594..15c834dd7 100644 --- a/term-utils/mesg.1 +++ b/term-utils/mesg.1 @@ -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 diff --git a/term-utils/mesg.c b/term-utils/mesg.c index 8714ad1aa..608f3cf61 100644 --- a/term-utils/mesg.c +++ b/term-utils/mesg.c @@ -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)