mesg.c revision 1.6 1 1.6 agc /* $NetBSD: mesg.c,v 1.6 2003/08/07 11:15:12 agc 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.6 agc * 3. Neither the name of the University nor the names of its contributors
21 1.3 cgd * may be used to endorse or promote products derived from this software
22 1.3 cgd * without specific prior written permission.
23 1.3 cgd *
24 1.3 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.3 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.3 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.3 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.3 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.3 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.3 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.3 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.3 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.3 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.3 cgd * SUCH DAMAGE.
35 1.3 cgd */
36 1.3 cgd
37 1.5 mikel #include <sys/cdefs.h>
38 1.5 mikel
39 1.3 cgd #ifndef lint
40 1.5 mikel __COPYRIGHT("@(#) Copyright (c) 1987, 1993\n\
41 1.5 mikel The Regents of the University of California. All rights reserved.\n");
42 1.3 cgd #endif /* not lint */
43 1.3 cgd
44 1.3 cgd #ifndef lint
45 1.4 jtc #if 0
46 1.4 jtc static char sccsid[] = "@(#)mesg.c 8.2 (Berkeley) 1/21/94";
47 1.4 jtc #endif
48 1.6 agc __RCSID("$NetBSD: mesg.c,v 1.6 2003/08/07 11:15:12 agc Exp $");
49 1.3 cgd #endif /* not lint */
50 1.3 cgd
51 1.3 cgd #include <sys/types.h>
52 1.3 cgd #include <sys/stat.h>
53 1.4 jtc
54 1.4 jtc #include <err.h>
55 1.4 jtc #include <errno.h>
56 1.3 cgd #include <stdio.h>
57 1.4 jtc #include <stdlib.h>
58 1.4 jtc #include <string.h>
59 1.4 jtc #include <unistd.h>
60 1.3 cgd
61 1.5 mikel int main __P((int, char **));
62 1.5 mikel
63 1.4 jtc int
64 1.3 cgd main(argc, argv)
65 1.3 cgd int argc;
66 1.4 jtc char *argv[];
67 1.3 cgd {
68 1.4 jtc struct stat sb;
69 1.4 jtc char *tty;
70 1.4 jtc int ch;
71 1.4 jtc
72 1.5 mikel while ((ch = getopt(argc, argv, "")) != -1)
73 1.4 jtc switch (ch) {
74 1.4 jtc case '?':
75 1.4 jtc default:
76 1.4 jtc goto usage;
77 1.4 jtc }
78 1.4 jtc argc -= optind;
79 1.4 jtc argv += optind;
80 1.3 cgd
81 1.4 jtc if ((tty = ttyname(STDERR_FILENO)) == NULL)
82 1.5 mikel err(2, "ttyname");
83 1.4 jtc if (stat(tty, &sb) < 0)
84 1.5 mikel err(2, "%s", tty);
85 1.4 jtc
86 1.4 jtc if (*argv == NULL) {
87 1.4 jtc if (sb.st_mode & S_IWGRP) {
88 1.4 jtc (void)fprintf(stderr, "is y\n");
89 1.3 cgd exit(0);
90 1.3 cgd }
91 1.4 jtc (void)fprintf(stderr, "is n\n");
92 1.3 cgd exit(1);
93 1.3 cgd }
94 1.4 jtc
95 1.4 jtc switch (*argv[0]) {
96 1.3 cgd case 'y':
97 1.4 jtc if (chmod(tty, sb.st_mode | S_IWGRP) < 0)
98 1.5 mikel err(2, "%s", tty);
99 1.3 cgd exit(0);
100 1.3 cgd case 'n':
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(1);
104 1.3 cgd }
105 1.3 cgd
106 1.4 jtc usage: (void)fprintf(stderr, "usage: mesg [y | n]\n");
107 1.4 jtc exit(2);
108 1.3 cgd }
109