mesg.c revision 1.5 1 1.5 mikel /* $NetBSD: mesg.c,v 1.5 1997/08/01 04:32:44 mikel Exp $ */
2 1.4 jtc
3 1.3 cgd /*
4 1.4 jtc * Copyright (c) 1987, 1993
5 1.4 jtc * The Regents of the University of California. All rights reserved.
6 1.3 cgd * (c) UNIX System Laboratories, Inc.
7 1.3 cgd * All or some portions of this file are derived from material licensed
8 1.3 cgd * to the University of California by American Telephone and Telegraph
9 1.3 cgd * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 1.3 cgd * the permission of UNIX System Laboratories, Inc.
11 1.3 cgd *
12 1.3 cgd * Redistribution and use in source and binary forms, with or without
13 1.3 cgd * modification, are permitted provided that the following conditions
14 1.3 cgd * are met:
15 1.3 cgd * 1. Redistributions of source code must retain the above copyright
16 1.3 cgd * notice, this list of conditions and the following disclaimer.
17 1.3 cgd * 2. Redistributions in binary form must reproduce the above copyright
18 1.3 cgd * notice, this list of conditions and the following disclaimer in the
19 1.3 cgd * documentation and/or other materials provided with the distribution.
20 1.3 cgd * 3. All advertising materials mentioning features or use of this software
21 1.3 cgd * must display the following acknowledgement:
22 1.3 cgd * This product includes software developed by the University of
23 1.3 cgd * California, Berkeley and its contributors.
24 1.3 cgd * 4. Neither the name of the University nor the names of its contributors
25 1.3 cgd * may be used to endorse or promote products derived from this software
26 1.3 cgd * without specific prior written permission.
27 1.3 cgd *
28 1.3 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 1.3 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 1.3 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 1.3 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 1.3 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 1.3 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 1.3 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 1.3 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 1.3 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 1.3 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 1.3 cgd * SUCH DAMAGE.
39 1.3 cgd */
40 1.3 cgd
41 1.5 mikel #include <sys/cdefs.h>
42 1.5 mikel
43 1.3 cgd #ifndef lint
44 1.5 mikel __COPYRIGHT("@(#) Copyright (c) 1987, 1993\n\
45 1.5 mikel The Regents of the University of California. All rights reserved.\n");
46 1.3 cgd #endif /* not lint */
47 1.3 cgd
48 1.3 cgd #ifndef lint
49 1.4 jtc #if 0
50 1.4 jtc static char sccsid[] = "@(#)mesg.c 8.2 (Berkeley) 1/21/94";
51 1.4 jtc #endif
52 1.5 mikel __RCSID("$NetBSD: mesg.c,v 1.5 1997/08/01 04:32:44 mikel Exp $");
53 1.3 cgd #endif /* not lint */
54 1.3 cgd
55 1.3 cgd #include <sys/types.h>
56 1.3 cgd #include <sys/stat.h>
57 1.4 jtc
58 1.4 jtc #include <err.h>
59 1.4 jtc #include <errno.h>
60 1.3 cgd #include <stdio.h>
61 1.4 jtc #include <stdlib.h>
62 1.4 jtc #include <string.h>
63 1.4 jtc #include <unistd.h>
64 1.3 cgd
65 1.5 mikel int main __P((int, char **));
66 1.5 mikel
67 1.4 jtc int
68 1.3 cgd main(argc, argv)
69 1.3 cgd int argc;
70 1.4 jtc char *argv[];
71 1.3 cgd {
72 1.4 jtc struct stat sb;
73 1.4 jtc char *tty;
74 1.4 jtc int ch;
75 1.4 jtc
76 1.5 mikel while ((ch = getopt(argc, argv, "")) != -1)
77 1.4 jtc switch (ch) {
78 1.4 jtc case '?':
79 1.4 jtc default:
80 1.4 jtc goto usage;
81 1.4 jtc }
82 1.4 jtc argc -= optind;
83 1.4 jtc argv += optind;
84 1.3 cgd
85 1.4 jtc if ((tty = ttyname(STDERR_FILENO)) == NULL)
86 1.5 mikel err(2, "ttyname");
87 1.4 jtc if (stat(tty, &sb) < 0)
88 1.5 mikel err(2, "%s", tty);
89 1.4 jtc
90 1.4 jtc if (*argv == NULL) {
91 1.4 jtc if (sb.st_mode & S_IWGRP) {
92 1.4 jtc (void)fprintf(stderr, "is y\n");
93 1.3 cgd exit(0);
94 1.3 cgd }
95 1.4 jtc (void)fprintf(stderr, "is n\n");
96 1.3 cgd exit(1);
97 1.3 cgd }
98 1.4 jtc
99 1.4 jtc switch (*argv[0]) {
100 1.3 cgd case 'y':
101 1.4 jtc if (chmod(tty, sb.st_mode | S_IWGRP) < 0)
102 1.5 mikel err(2, "%s", tty);
103 1.3 cgd exit(0);
104 1.3 cgd case 'n':
105 1.4 jtc if (chmod(tty, sb.st_mode & ~S_IWGRP) < 0)
106 1.5 mikel err(2, "%s", tty);
107 1.3 cgd exit(1);
108 1.3 cgd }
109 1.3 cgd
110 1.4 jtc usage: (void)fprintf(stderr, "usage: mesg [y | n]\n");
111 1.4 jtc exit(2);
112 1.3 cgd }
113