Commit | Line | Data |
---|---|---|
56b5a10f | 1 | /* |
eb2348ca KB |
2 | * Copyright (c) 1987, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
adb35f79 KB |
4 | * (c) UNIX System Laboratories, Inc. |
5 | * All or some portions of this file are derived from material licensed | |
6 | * to the University of California by American Telephone and Telegraph | |
7 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with | |
8 | * the permission of UNIX System Laboratories, Inc. | |
56b5a10f | 9 | * |
f15db449 | 10 | * %sccs.include.redist.c% |
56b5a10f KB |
11 | */ |
12 | ||
13 | #ifndef lint | |
eb2348ca KB |
14 | static char copyright[] = |
15 | "@(#) Copyright (c) 1987, 1993\n\ | |
16 | The Regents of the University of California. All rights reserved.\n"; | |
56b5a10f KB |
17 | #endif /* not lint */ |
18 | ||
19 | #ifndef lint | |
adb35f79 | 20 | static char sccsid[] = "@(#)mesg.c 8.2 (Berkeley) %G%"; |
56b5a10f KB |
21 | #endif /* not lint */ |
22 | ||
69d8f2f4 BJ |
23 | #include <sys/types.h> |
24 | #include <sys/stat.h> | |
e8694a61 | 25 | |
5b98de6f | 26 | #include <err.h> |
b8432c0e | 27 | #include <errno.h> |
56b5a10f | 28 | #include <stdio.h> |
b8432c0e KB |
29 | #include <stdlib.h> |
30 | #include <string.h> | |
e8694a61 | 31 | #include <unistd.h> |
69d8f2f4 | 32 | |
b8432c0e | 33 | int |
69d8f2f4 | 34 | main(argc, argv) |
56b5a10f | 35 | int argc; |
b8432c0e | 36 | char *argv[]; |
69d8f2f4 | 37 | { |
e8694a61 | 38 | struct stat sb; |
b8432c0e KB |
39 | char *tty; |
40 | int ch; | |
69d8f2f4 | 41 | |
b8432c0e | 42 | while ((ch = getopt(argc, argv, "")) != EOF) |
e8694a61 | 43 | switch (ch) { |
b8432c0e KB |
44 | case '?': |
45 | default: | |
5b98de6f | 46 | goto usage; |
b8432c0e KB |
47 | } |
48 | argc -= optind; | |
49 | argv += optind; | |
50 | ||
e8694a61 | 51 | if ((tty = ttyname(STDERR_FILENO)) == NULL) |
5b98de6f | 52 | err(1, "ttyname"); |
e8694a61 | 53 | if (stat(tty, &sb) < 0) |
5b98de6f | 54 | err(1, "%s", tty); |
b8432c0e KB |
55 | |
56 | if (*argv == NULL) { | |
e8694a61 | 57 | if (sb.st_mode & S_IWGRP) { |
b8432c0e | 58 | (void)fprintf(stderr, "is y\n"); |
56b5a10f | 59 | exit(0); |
69d8f2f4 | 60 | } |
b8432c0e | 61 | (void)fprintf(stderr, "is n\n"); |
56b5a10f KB |
62 | exit(1); |
63 | } | |
5b98de6f | 64 | |
e8694a61 | 65 | switch (*argv[0]) { |
56b5a10f | 66 | case 'y': |
e8694a61 | 67 | if (chmod(tty, sb.st_mode | S_IWGRP) < 0) |
5b98de6f | 68 | err(1, "%s", tty); |
56b5a10f KB |
69 | exit(0); |
70 | case 'n': | |
e8694a61 | 71 | if (chmod(tty, sb.st_mode & ~S_IWGRP) < 0) |
5b98de6f | 72 | err(1, "%s", tty); |
56b5a10f | 73 | exit(1); |
56b5a10f | 74 | } |
69d8f2f4 | 75 | |
5b98de6f | 76 | usage: (void)fprintf(stderr, "usage: mesg [y | n]\n"); |
b8432c0e | 77 | exit(2); |
69d8f2f4 | 78 | } |