diff options
author | Sami Kerola | 2018-08-02 20:35:51 +0200 |
---|---|---|
committer | Karel Zak | 2018-08-03 12:27:02 +0200 |
commit | 8dd5832395c6a0b12e11b37c062e4c11be3c82ef (patch) | |
tree | a0da27e492def5c7dc8ad0e5a2a1e9da9425a85d /term-utils/mesg.c | |
parent | tests: update lscpu tests (diff) | |
download | kernel-qcow2-util-linux-8dd5832395c6a0b12e11b37c062e4c11be3c82ef.tar.gz kernel-qcow2-util-linux-8dd5832395c6a0b12e11b37c062e4c11be3c82ef.tar.xz kernel-qcow2-util-linux-8dd5832395c6a0b12e11b37c062e4c11be3c82ef.zip |
mesg: do not print 'ttyname failed' message unless --verbose requested
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>
Diffstat (limited to 'term-utils/mesg.c')
-rw-r--r-- | term-utils/mesg.c | 5 |
1 files changed, 5 insertions, 0 deletions
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) |