From howardjp@wam.umd.edu Wed Aug 11 05:22:18 1999
Return-Path: <howardjp@wam.umd.edu>
Received: from po3.wam.umd.edu (po3.wam.umd.edu [128.8.10.165])
	by hub.freebsd.org (Postfix) with ESMTP id 1675714DF5
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 11 Aug 1999 05:22:11 -0700 (PDT)
	(envelope-from howardjp@wam.umd.edu)
Received: from rac10.wam.umd.edu (root@rac10.wam.umd.edu [128.8.10.150])
	by po3.wam.umd.edu (8.9.3/8.9.3) with ESMTP id IAA11286
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 11 Aug 1999 08:21:05 -0400 (EDT)
Received: from rac10.wam.umd.edu (sendmail@localhost [127.0.0.1])
	by rac10.wam.umd.edu (8.9.3/8.9.3) with SMTP id IAA04691
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 11 Aug 1999 08:21:04 -0400 (EDT)
Received: (from howardjp@localhost)
	by rac10.wam.umd.edu (8.9.3/8.9.3) id IAA04687
	for FreeBSD-gnats-submit@freebsd.org; Wed, 11 Aug 1999 08:21:04 -0400 (EDT)
Message-Id: <199908111221.IAA04687@rac10.wam.umd.edu>
Date: Wed, 11 Aug 1999 08:21:04 -0400 (EDT)
From: James Howard <howardjp@wam.umd.edu>
Reply-To: howardjp@wam.umd.edu
To: FreeBSD-gnats-submit@freebsd.org
Subject: Extensions to mesg(1)
X-Send-Pr-Version: 3.2

>Number:         13073
>Category:       bin
>Synopsis:       Extensions to mesg(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    johan
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Aug 11 05:30:04 PDT 1999
>Closed-Date:    Wed Jul 24 08:59:20 PDT 2002
>Last-Modified:  Wed Jul 24 08:59:20 PDT 2002
>Originator:     James Howard
>Release:        FreeBSD 3.2-STABLE i386
>Organization:
University of Maryland
>Environment:

FreeBSD byzantine 3.2-STABLE FreeBSD 3.2-STABLE #5: Sat Aug  7 23:43:54 GMT 1999     root@byzantine:/usr/src/sys/compile/BYZANTINE  i386

>Description:

Often when I am logged in via telnet to a FreeBSD host, I use Lynx to
download files.  If it is a large download, the arrival of talk 
requests or write messages can mess up the display of Lynx's status.  
This patch to mesg(1) will allow you to use "mesg -t tty" report or 
change the status of tty instead of the current.  I do this often 
from a second telnet session.

>How-To-Repeat:

Irrelevant.

>Fix:

diff -c /usr/src/usr.bin/mesg/mesg.1 /usr/local/src/usr.bin/mesg/mesg.1
*** /usr/src/usr.bin/mesg/mesg.1	Thu Jul 24 06:59:00 1997
--- /usr/local/src/usr.bin/mesg/mesg.1	Wed Aug 11 00:36:42 1999
***************
*** 40,45 ****
--- 40,46 ----
  .Nd display (do not display) messages from other users
  .Sh SYNOPSIS
  .Nm
+ .Op Fl t Ar tty
  .Op Cm n | Cm y
  .Sh DESCRIPTION
  The
***************
*** 54,60 ****
  may display messages on the terminal.
  .Pp
  Options available:
! .Bl -tag -width flag
  .It Cm n
  Disallows messages.
  .It Cm y
--- 55,65 ----
  may display messages on the terminal.
  .Pp
  Options available:
! .Bl -tag -width 8n
! .It Fl t Ar tty
! Report or change the status of 
! .Ar tty
! rather than the current terminal.
  .It Cm n
  Disallows messages.
  .It Cm y
diff -c /usr/src/usr.bin/mesg/mesg.c /usr/local/src/usr.bin/mesg/mesg.c
*** /usr/src/usr.bin/mesg/mesg.c	Thu Jul 24 06:59:00 1997
--- /usr/local/src/usr.bin/mesg/mesg.c	Wed Aug 11 00:33:53 1999
***************
*** 54,59 ****
--- 54,60 ----
  #include <sys/stat.h>
  
  #include <err.h>
+ #include <paths.h>
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
***************
*** 70,77 ****
  	char *tty;
  	int ch;
  
! 	while ((ch = getopt(argc, argv, "")) != -1)
  		switch (ch) {
  		case '?':
  		default:
  			usage();
--- 71,82 ----
  	char *tty;
  	int ch;
  
! 	tty = NULL;
! 	while ((ch = getopt(argc, argv, "t:")) != -1)
  		switch (ch) {
+ 		case 't':
+ 			tty = optarg;
+ 			break;
  		case '?':
  		default:
  			usage();
***************
*** 79,86 ****
  	argc -= optind;
  	argv += optind;
  
! 	if ((tty = ttyname(STDERR_FILENO)) == NULL)
! 		err(1, "ttyname");
  	if (stat(tty, &sb) < 0)
  		err(1, "%s", tty);
  
--- 84,93 ----
  	argc -= optind;
  	argv += optind;
  
! 	if (tty == NULL) 
! 		if ((tty = ttyname(STDERR_FILENO)) == NULL)
! 			err(1, "ttyname");
! 	(void)chdir(_PATH_DEV);
  	if (stat(tty, &sb) < 0)
  		err(1, "%s", tty);
  
***************
*** 111,116 ****
  static void
  usage()
  {
! 	(void)fprintf(stderr, "usage: mesg [y | n]\n");
  	exit(2);
  }
--- 118,123 ----
  static void
  usage()
  {
! 	(void)fprintf(stderr, "usage: mesg [-t tty] [y | n]\n");
  	exit(2);
  }

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->billf 
Responsible-Changed-By: billf 
Responsible-Changed-When: Wed Aug 11 07:17:05 PDT 1999 
Responsible-Changed-Why:  
I'll look at this. 
Responsible-Changed-From-To: billf->johan 
Responsible-Changed-By: johan 
Responsible-Changed-When: Tue Jul 9 10:34:01 PDT 2002 
Responsible-Changed-Why:  
Bill suggested I should have a look at this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=13073 
State-Changed-From-To: open->analyzed 
State-Changed-By: johan 
State-Changed-When: Thu Jul 11 11:13:08 PDT 2002 
State-Changed-Why:  
This seems to be a good change. 
Pending no objection from -standards and -arch 
I will commit this soon. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=13072 
State-Changed-From-To: open->analyzed 
State-Changed-By: johan 
State-Changed-When: Thu Jul 11 11:13:08 PDT 2002 
State-Changed-Why:  
This seems to be a good change.  
Pending no objection from -standards and -arch  
I will commit this soon.  



http://www.freebsd.org/cgi/query-pr.cgi?pr=13073 

From: Cyrille Lefevre <cyrille.lefevre@laposte.net>
To: freebsd-gnats-submit@FreeBSD.org, howardjp@wam.umd.edu
Cc: freebsd arch <freebsd-arch@FreeBSD.org>
Subject: Re: bin/13073: Extensions to mesg(1)
Date: Wed, 24 Jul 2002 16:44:28 +0200

 Hi,
 
 IMHO, there is no real need for such `-t tty' option.
 
 for instance, `mesg n 2< /dev/ttyXX' will do it.
 
 however, to match SUSv3, a simple indirection should suffice.
 
 http://www.opengroup.org/onlinepubs/007904975/utilities/mesg.html
 
 DESCRIPTION
 	...
 	The terminal device affected shall be determined by searching for
 	the first terminal in the sequence of devices associated with
 	standard input, standard output, and standard error, respectively.
 	...
 STDOUT
 	If no operand is specified, mesg shall display the current
 	terminal state in an unspecified format.
 STDERR
 	The standard error shall be used only for diagnostic messages.
 EXIT STATUS
 	The following exit values shall be returned:
 	 0 Receiving messages is allowed. 
 	 1 Receiving messages is not allowed. 
 	>1 An error occurred. 
 
 also, biff and mesg don't match. the former display it's diagnostic
 message to stdout and the later to stderr.
 
 here is a patch to sync mesg w/ SUSv3.
 
 * string.h not needed
 * try stdin, stdout and stderr in turn
 * err(1 -> err(2
 * fprintf(stderr -> printf(
 * other changes reduce diffs w/ biff.
 
 Index: /usr/src/usr.bin/mesg/Makefile
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/mesg/Makefile,v
 retrieving revision 1.1.1.1
 diff -u -r1.1.1.1 Makefile
 --- /usr/src/usr.bin/mesg/Makefile	27 May 1994 12:30:44 -0000	1.1.1.1
 +++ /usr/src/usr.bin/mesg/Makefile	24 Jul 2002 14:25:44 -0000
 @@ -1,5 +1,6 @@
  #	@(#)Makefile	8.1 (Berkeley) 6/6/93
  
  PROG=	mesg
 +WARNS?=	2
  
  .include <bsd.prog.mk>
 Index: /usr/src/usr.bin/mesg/mesg.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/mesg/mesg.c,v
 retrieving revision 1.4
 diff -u -r1.4 mesg.c
 --- /usr/src/usr.bin/mesg/mesg.c	28 Aug 1999 01:03:59 -0000	1.4
 +++ /usr/src/usr.bin/mesg/mesg.c	24 Jul 2002 14:39:28 -0000
 @@ -56,7 +56,6 @@
  #include <err.h>
  #include <stdio.h>
  #include <stdlib.h>
 -#include <string.h>
  #include <unistd.h>
  
  static void usage __P((void));
 @@ -79,33 +78,32 @@
  	argc -= optind;
  	argv += optind;
  
 -	if ((tty = ttyname(STDERR_FILENO)) == NULL)
 -		err(1, "ttyname");
 +	if ((tty = ttyname(STDIN_FILENO)) == NULL &&
 +	    (tty = ttyname(STDOUT_FILENO)) == NULL &&
 +	    (tty = ttyname(STDERR_FILENO)) == NULL)
 +		err(2, "unknown tty");
 +
  	if (stat(tty, &sb) < 0)
 -		err(1, "%s", tty);
 +		err(2, "%s", tty);
  
  	if (*argv == NULL) {
 -		if (sb.st_mode & S_IWGRP) {
 -			(void)fprintf(stderr, "is y\n");
 -			exit(0);
 -		}
 -		(void)fprintf(stderr, "is n\n");
 -		exit(1);
 +		(void)printf("is %s\n", sb.st_mode & S_IWGRP ? "y" : "n");
 +		return(sb.st_mode & S_IWGRP ? 0 : 1);
  	}
  
 -	switch (*argv[0]) {
 +	switch (argv[0][0]) {
  	case 'y':
  		if (chmod(tty, sb.st_mode | S_IWGRP) < 0)
 -			err(1, "%s", tty);
 -		exit(0);
 +			err(2, "%s", tty);
 +		break;
  	case 'n':
  		if (chmod(tty, sb.st_mode & ~S_IWGRP) < 0)
 -			err(1, "%s", tty);
 -		exit(1);
 +			err(2, "%s", tty);
 +		break;
 +	default:
 +		usage();
  	}
 -
 -	usage();
 -	return(0);
 +	return(sb.st_mode & S_IWGRP ? 0 : 1);
  }
  
  static void
 
 PS : see PR #13072 for a similar patch to biff.
 
 Cyrille.
 -- 
 Cyrille Lefevre                 mailto:cyrille.lefevre@laposte.net

From: Johan Karlsson <johan@FreeBSD.org>
To: Cyrille Lefevre <cyrille.lefevre@laposte.net>
Cc: freebsd-gnats-submit@FreeBSD.org, howardjp@wam.umd.edu,
	arch@FreeBSD.org
Subject: Re: bin/13073: Extensions to mesg(1)
Date: Wed, 24 Jul 2002 17:01:49 +0200

 Tim (tjr) has already made mesg(1) SuSv3 compiant in current.
 
 /Johan
 
 --
 Johan Karlsson		mailto:johan@FreeBSD.org
State-Changed-From-To: analyzed->closed 
State-Changed-By: johan 
State-Changed-When: Wed Jul 24 08:58:51 PDT 2002 
State-Changed-Why:  
One can now use redirection of stdin to select 
another tty. 

# mesg n < /dev/ttyp1 

I think this is good enough. If you don't, please 
argu your case on freebsd-arch@freebsd.org. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=13073 
>Unformatted:
