summaryrefslogtreecommitdiffstats
path: root/usr.bin/mesg/mesg.c
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-05-06 04:33:04 +0000
committertjr <tjr@FreeBSD.org>2002-05-06 04:33:04 +0000
commit2a4292262e25e24b26f8919fa92465eaf087483c (patch)
tree9afc5ae665ac4d9aa52d78234d6183202b427d49 /usr.bin/mesg/mesg.c
parent864cb02be27117c8975516a1c4ac29e99604c0ba (diff)
downloadFreeBSD-src-2a4292262e25e24b26f8919fa92465eaf087483c.zip
FreeBSD-src-2a4292262e25e24b26f8919fa92465eaf087483c.tar.gz
Affect the first of stdin, stdout and stderr that is attached to a terminal.
Write status information to stdout instead of stderr. Exit status when an error occurs musn't be 1, that is reserved for indicating that messages are disabled. These changes bring mesg(1) up to SUSv3 conformance. Reviewed by: mike
Diffstat (limited to 'usr.bin/mesg/mesg.c')
-rw-r--r--usr.bin/mesg/mesg.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/usr.bin/mesg/mesg.c b/usr.bin/mesg/mesg.c
index d80acb6..dcd14c3 100644
--- a/usr.bin/mesg/mesg.c
+++ b/usr.bin/mesg/mesg.c
@@ -79,28 +79,30 @@ main(argc, argv)
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, "ttyname");
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");
+ (void)puts("is y");
exit(0);
}
- (void)fprintf(stderr, "is n\n");
+ (void)puts("is n");
exit(1);
}
switch (*argv[0]) {
case 'y':
if (chmod(tty, sb.st_mode | S_IWGRP) < 0)
- err(1, "%s", tty);
+ err(2, "%s", tty);
exit(0);
case 'n':
if (chmod(tty, sb.st_mode & ~S_IWGRP) < 0)
- err(1, "%s", tty);
+ err(2, "%s", tty);
exit(1);
}
OpenPOWER on IntegriCloud