Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 Jul 2002 16:44:28 +0200
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)
Message-ID:  <20020724144427.GA13514@gits.dyndns.org>

next in thread | raw e-mail | index | archive | help
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

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020724144427.GA13514>