1 /* 2 * Copyright (c) 1987, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char copyright[] = 10 "@(#) Copyright (c) 1987, 1993\n\ 11 The Regents of the University of California. All rights reserved.\n"; 12 #endif /* not lint */ 13 14 #ifndef lint 15 static char sccsid[] = "@(#)mesg.c 8.1 (Berkeley) 06/06/93"; 16 #endif /* not lint */ 17 18 #include <sys/types.h> 19 #include <sys/stat.h> 20 21 #include <err.h> 22 #include <errno.h> 23 #include <stdio.h> 24 #include <stdlib.h> 25 #include <string.h> 26 #include <unistd.h> 27 28 int 29 main(argc, argv) 30 int argc; 31 char *argv[]; 32 { 33 struct stat sb; 34 char *tty; 35 int ch; 36 37 while ((ch = getopt(argc, argv, "")) != EOF) 38 switch (ch) { 39 case '?': 40 default: 41 goto usage; 42 } 43 argc -= optind; 44 argv += optind; 45 46 if ((tty = ttyname(STDERR_FILENO)) == NULL) 47 err(1, "ttyname"); 48 if (stat(tty, &sb) < 0) 49 err(1, "%s", tty); 50 51 if (*argv == NULL) { 52 if (sb.st_mode & S_IWGRP) { 53 (void)fprintf(stderr, "is y\n"); 54 exit(0); 55 } 56 (void)fprintf(stderr, "is n\n"); 57 exit(1); 58 } 59 60 switch (*argv[0]) { 61 case 'y': 62 if (chmod(tty, sb.st_mode | S_IWGRP) < 0) 63 err(1, "%s", tty); 64 exit(0); 65 case 'n': 66 if (chmod(tty, sb.st_mode & ~S_IWGRP) < 0) 67 err(1, "%s", tty); 68 exit(1); 69 } 70 71 usage: (void)fprintf(stderr, "usage: mesg [y | n]\n"); 72 exit(2); 73 } 74