util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mesg: do not print 'ttyname failed' message unless --verbose requested
@ 2018-08-01 21:26 Sami Kerola
  2018-08-02  8:51 ` Karel Zak
  0 siblings, 1 reply; 4+ messages in thread
From: Sami Kerola @ 2018-08-01 21:26 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

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);
+	}
 	if ((fd = open(tty, O_RDONLY)) < 0)
 		err(MESG_EXIT_FAILURE, _("cannot open %s"), tty);
 	if (fstat(fd, &sb))
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mesg: do not print 'ttyname failed' message unless --verbose requested
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Karel Zak @ 2018-08-02  8:51 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

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 ...


   Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mesg: do not print 'ttyname failed' message unless --verbose requested
  2018-08-02  8:51 ` Karel Zak
@ 2018-08-02 18:38   ` Sami Kerola
  2018-08-03 10:30     ` Karel Zak
  0 siblings, 1 reply; 4+ messages in thread
From: Sami Kerola @ 2018-08-02 18:38 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

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/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mesg: do not print 'ttyname failed' message unless --verbose requested
  2018-08-02 18:38   ` Sami Kerola
@ 2018-08-03 10:30     ` Karel Zak
  0 siblings, 0 replies; 4+ messages in thread
From: Karel Zak @ 2018-08-03 10:30 UTC (permalink / raw)
  To: kerolasa; +Cc: util-linux

On Thu, Aug 02, 2018 at 07:38:08PM +0100, Sami Kerola wrote:
> 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:

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@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-08-03 12:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2018-08-03 10:30     ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).