Home | History | Annotate | Line # | Download | only in mesg
mesg.c revision 1.4
      1  1.4  jtc /*	$NetBSD: mesg.c,v 1.4 1994/12/23 07:16:32 jtc 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.3  cgd #ifndef lint
     42  1.4  jtc static char copyright[] =
     43  1.4  jtc "@(#) Copyright (c) 1987, 1993\n\
     44  1.4  jtc 	The Regents of the University of California.  All rights reserved.\n";
     45  1.3  cgd #endif /* not lint */
     46  1.3  cgd 
     47  1.3  cgd #ifndef lint
     48  1.4  jtc #if 0
     49  1.4  jtc static char sccsid[] = "@(#)mesg.c	8.2 (Berkeley) 1/21/94";
     50  1.4  jtc #endif
     51  1.4  jtc static char rcsid[] = "$NetBSD: mesg.c,v 1.4 1994/12/23 07:16:32 jtc Exp $";
     52  1.3  cgd #endif /* not lint */
     53  1.3  cgd 
     54  1.3  cgd #include <sys/types.h>
     55  1.3  cgd #include <sys/stat.h>
     56  1.4  jtc 
     57  1.4  jtc #include <err.h>
     58  1.4  jtc #include <errno.h>
     59  1.3  cgd #include <stdio.h>
     60  1.4  jtc #include <stdlib.h>
     61  1.4  jtc #include <string.h>
     62  1.4  jtc #include <unistd.h>
     63  1.3  cgd 
     64  1.4  jtc int
     65  1.3  cgd main(argc, argv)
     66  1.3  cgd 	int argc;
     67  1.4  jtc 	char *argv[];
     68  1.3  cgd {
     69  1.4  jtc 	struct stat sb;
     70  1.4  jtc 	char *tty;
     71  1.4  jtc 	int ch;
     72  1.4  jtc 
     73  1.4  jtc 	while ((ch = getopt(argc, argv, "")) != EOF)
     74  1.4  jtc 		switch (ch) {
     75  1.4  jtc 		case '?':
     76  1.4  jtc 		default:
     77  1.4  jtc 			goto usage;
     78  1.4  jtc 		}
     79  1.4  jtc 	argc -= optind;
     80  1.4  jtc 	argv += optind;
     81  1.3  cgd 
     82  1.4  jtc 	if ((tty = ttyname(STDERR_FILENO)) == NULL)
     83  1.4  jtc 		err(1, "ttyname");
     84  1.4  jtc 	if (stat(tty, &sb) < 0)
     85  1.4  jtc 		err(1, "%s", tty);
     86  1.4  jtc 
     87  1.4  jtc 	if (*argv == NULL) {
     88  1.4  jtc 		if (sb.st_mode & S_IWGRP) {
     89  1.4  jtc 			(void)fprintf(stderr, "is y\n");
     90  1.3  cgd 			exit(0);
     91  1.3  cgd 		}
     92  1.4  jtc 		(void)fprintf(stderr, "is n\n");
     93  1.3  cgd 		exit(1);
     94  1.3  cgd 	}
     95  1.4  jtc 
     96  1.4  jtc 	switch (*argv[0]) {
     97  1.3  cgd 	case 'y':
     98  1.4  jtc 		if (chmod(tty, sb.st_mode | S_IWGRP) < 0)
     99  1.4  jtc 			err(1, "%s", tty);
    100  1.3  cgd 		exit(0);
    101  1.3  cgd 	case 'n':
    102  1.4  jtc 		if (chmod(tty, sb.st_mode & ~S_IWGRP) < 0)
    103  1.4  jtc 			err(1, "%s", tty);
    104  1.3  cgd 		exit(1);
    105  1.3  cgd 	}
    106  1.3  cgd 
    107  1.4  jtc usage:	(void)fprintf(stderr, "usage: mesg [y | n]\n");
    108  1.4  jtc 	exit(2);
    109  1.3  cgd }
    110