Re: [PATCH] mesg: do not print 'ttyname failed' message unless --verbose requested

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 02, 2018 at 07:38:08PM +0100, Sami Kerola wrote:
> On 2 August 2018 at 09:51, Karel Zak <kzak@xxxxxxxxxx> wrote:
> > On Wed, Aug 01, 2018 at 10:26:44PM +0100, Sami Kerola wrote:
> >> 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.
> >>
> >> Reference: https://www.google.com/search?q=mesg+ttyname+failed
> >> Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
> >> ---
> >>  term-utils/mesg.c | 7 +++++--
> >>  1 file changed, 5 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/term-utils/mesg.c b/term-utils/mesg.c
> >> index 8714ad1aa..7c4e390bb 100644
> >> --- a/term-utils/mesg.c
> >> +++ b/term-utils/mesg.c
> >> @@ -121,8 +121,11 @@ int main(int argc, char *argv[])
> >>       argc -= optind;
> >>       argv += optind;
> >>
> >> -     if ((tty = ttyname(STDERR_FILENO)) == NULL)
> >> -             err(MESG_EXIT_FAILURE, _("ttyname failed"));
> >> +     if ((tty = ttyname(STDERR_FILENO)) == NULL) {
> >> +             if (verbose == TRUE)
> >> +                     err(MESG_EXIT_FAILURE, _("ttyname failed"));
> >> +             exit(MESG_EXIT_FAILURE);
> >> +     }
> >
> > What about:
> >
> > if (isatty(STDERR_FILENO)) {
> >     if (verbose)
> >         warnx(_("no tty"));
> >     exit(MESG_EXIT_FAILURE);
> > }
> >
> > tty = ttyname(STDERR_FILENO);
> > if (!tty)
> >    ... the current code ...
> 
> Hi Karel
> 
> That's probably better. I pushed that version to my remote branch
> 'mesg' and made pull request:

It's mistake to copy & past without testing. Should be 

    if (!isatty(STDERR_FILENO))

Fixed. I have also added a note to the man page as hide a warning is
little bit controversial.

    Karel


-- 
 Karel Zak  <kzak@xxxxxxxxxx>
 http://karelzak.blogspot.com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux