Bug 13073

Summary: Extensions to mesg(1)
Product: Base System Reporter: howardjp <howardjp>
Component: binAssignee: Johan Karlsson <johan>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 3.2-STABLE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description howardjp 1999-08-11 13:30:04 UTC
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.
Comment 1 bill fumerola freebsd_committer freebsd_triage 1999-08-11 15:17:05 UTC
Responsible Changed
From-To: freebsd-bugs->billf

I'll look at this. 
Comment 2 Johan Karlsson freebsd_committer freebsd_triage 2002-07-09 18:34:01 UTC
Responsible Changed
From-To: billf->johan

Bill suggested I should have a look at this.
Comment 3 Johan Karlsson freebsd_committer freebsd_triage 2002-07-11 19:13:08 UTC
State Changed
From-To: open->analyzed

This seems to be a good change. 
Pending no objection from -standards and -arch 
I will commit this soon.
Comment 4 Johan Karlsson freebsd_committer freebsd_triage 2002-07-11 19:13:08 UTC
State Changed
From-To: open->analyzed

This seems to be a good change.  
Pending no objection from -standards and -arch  
I will commit this soon.
Comment 5 Cyrille Lefevre 2002-07-24 15:44:28 UTC
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
Comment 6 Johan Karlsson freebsd_committer freebsd_triage 2002-07-24 16:01:49 UTC
Tim (tjr) has already made mesg(1) SuSv3 compiant in current.

/Johan

--
Johan Karlsson		mailto:johan@FreeBSD.org
Comment 7 Johan Karlsson freebsd_committer freebsd_triage 2002-07-24 16:58:51 UTC
State Changed
From-To: analyzed->closed

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.