All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: Karel Zak <kzak@redhat.com>
Cc: util-linux <util-linux@vger.kernel.org>
Subject: Re: [PATCH] mesg: do not print 'ttyname failed' message unless --verbose requested
Date: Thu, 2 Aug 2018 19:38:08 +0100	[thread overview]
Message-ID: <CAG27Bk0qkNb=0K+X0aMmQBL96OWhOLL1ZZov1SSm8PUa_Mjrtw@mail.gmail.com> (raw)
In-Reply-To: <20180802085117.vwbtc7kwkcphhelv@ws.net.home>

On 2 August 2018 at 09:51, Karel Zak <kzak@redhat.com> 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@iki.fi>
>> ---
>>  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:

https://github.com/karelzak/util-linux/pull/675

-- 
Sami Kerola
http://www.iki.fi/kerolasa/

  reply	other threads:[~2018-08-02 20:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-01 21:26 [PATCH] mesg: do not print 'ttyname failed' message unless --verbose requested Sami Kerola
2018-08-02  8:51 ` Karel Zak
2018-08-02 18:38   ` Sami Kerola [this message]
2018-08-03 10:30     ` Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAG27Bk0qkNb=0K+X0aMmQBL96OWhOLL1ZZov1SSm8PUa_Mjrtw@mail.gmail.com' \
    --to=kerolasa@iki.fi \
    --cc=kerolasa@gmail.com \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.