xref: /onnv-gate/usr/src/cmd/ttymon/tmglobal.c (revision 9300:38fba18c3b97)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*9300SNobutomo.Nakano@Sun.COM  * Common Development and Distribution License (the "License").
6*9300SNobutomo.Nakano@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*9300SNobutomo.Nakano@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
260Sstevel@tonic-gate /*	  All Rights Reserved  	*/
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <stdio.h>
290Sstevel@tonic-gate #include <poll.h>
300Sstevel@tonic-gate #include <signal.h>
310Sstevel@tonic-gate #include <sys/resource.h>
320Sstevel@tonic-gate #include <sac.h>
330Sstevel@tonic-gate #include "tmstruct.h"
340Sstevel@tonic-gate #include "ttymon.h"
350Sstevel@tonic-gate 
360Sstevel@tonic-gate /*
370Sstevel@tonic-gate  *	global fd and fp
380Sstevel@tonic-gate  */
390Sstevel@tonic-gate FILE	*Logfp = NULL;		/* for log file			*/
400Sstevel@tonic-gate int	Lckfd;			/* for pid file			*/
410Sstevel@tonic-gate int	Sfd, Pfd;		/* for sacpipe and pmpipe 	*/
420Sstevel@tonic-gate int	PCpipe[2];		/* pipe between Parent & Children */
430Sstevel@tonic-gate #ifdef	DEBUG
440Sstevel@tonic-gate FILE	*Debugfp = NULL;	/* for debug file		*/
450Sstevel@tonic-gate #endif
460Sstevel@tonic-gate 
470Sstevel@tonic-gate char	State = PM_STARTING;	/* current state			*/
480Sstevel@tonic-gate char	*Istate;		/* initial state			*/
490Sstevel@tonic-gate char	*Tag;			/* port monitor tag			*/
500Sstevel@tonic-gate int	Maxfiles;		/* Max number of open files		*/
510Sstevel@tonic-gate int	Maxfds;			/* Max no of devices ttymon can monitor */
520Sstevel@tonic-gate 
530Sstevel@tonic-gate int	Reread_flag = FALSE;	/* reread pmtab flag			*/
540Sstevel@tonic-gate 
550Sstevel@tonic-gate int	Retry;			/* retry open_device flag		*/
560Sstevel@tonic-gate 
570Sstevel@tonic-gate struct  pmtab *PMtab = NULL;	/* head pointer to pmtab linked list 	*/
580Sstevel@tonic-gate int	Nentries = 0;		/* # of entries in pmtab linked list	*/
590Sstevel@tonic-gate 
600Sstevel@tonic-gate struct  Gdef Gdef[MAXDEFS];	/* array to hold entries in /etc/ttydefs */
610Sstevel@tonic-gate int	Ndefs = 0;		/* highest index to Gdef that was used   */
620Sstevel@tonic-gate long	Mtime = 0;		/* last modification time of ttydefs	 */
630Sstevel@tonic-gate 
64*9300SNobutomo.Nakano@Sun.COM struct pollfd *Pollp;		/* ptr to an array of poll struct	*/
650Sstevel@tonic-gate int	Npollfd;		/* size of the pollfd array		 */
660Sstevel@tonic-gate 
670Sstevel@tonic-gate struct Gdef DEFAULT = {		/* default terminal settings	*/
680Sstevel@tonic-gate 	"default",
690Sstevel@tonic-gate 	"9600",
700Sstevel@tonic-gate 	"9600 sane",
710Sstevel@tonic-gate 	0,
72*9300SNobutomo.Nakano@Sun.COM 	/*
730Sstevel@tonic-gate 	 * next label is set to 4800 so we can start searching ttydefs.
74*9300SNobutomo.Nakano@Sun.COM 	 * if 4800 is not in ttydefs, we will loop back to use DEFAULT
750Sstevel@tonic-gate 	 */
760Sstevel@tonic-gate 	"4800"
770Sstevel@tonic-gate };
780Sstevel@tonic-gate 
790Sstevel@tonic-gate uid_t	Uucp_uid = 5;		/* owner's uid for bi-directional ports	*/
800Sstevel@tonic-gate gid_t	Tty_gid = 7;		/* group id for all tty devices		*/
810Sstevel@tonic-gate 
820Sstevel@tonic-gate /*
830Sstevel@tonic-gate  * Nlocked - 	number of ports that are either locked or have active
840Sstevel@tonic-gate  *		sessions not under this ttymon.
850Sstevel@tonic-gate  */
860Sstevel@tonic-gate int	Nlocked = 0;
870Sstevel@tonic-gate 
880Sstevel@tonic-gate /* original rlimit value */
890Sstevel@tonic-gate struct	rlimit	Rlimit;
900Sstevel@tonic-gate 
910Sstevel@tonic-gate /*
920Sstevel@tonic-gate  * places to remember original signal dispositions and masks
930Sstevel@tonic-gate  */
940Sstevel@tonic-gate 
950Sstevel@tonic-gate sigset_t	Origmask;		/* original signal mask */
960Sstevel@tonic-gate struct	sigaction	Sigalrm;	/* SIGALRM */
970Sstevel@tonic-gate struct	sigaction	Sigcld;		/* SIGCLD */
980Sstevel@tonic-gate struct	sigaction	Sigint;		/* SIGINT */
990Sstevel@tonic-gate struct	sigaction	Sigpoll;	/* SIGPOLL */
100*9300SNobutomo.Nakano@Sun.COM struct	sigaction	Sigquit;	/* SIGQUIT */
1010Sstevel@tonic-gate struct	sigaction	Sigterm;	/* SIGTERM */
1020Sstevel@tonic-gate #ifdef	DEBUG
1030Sstevel@tonic-gate struct	sigaction	Sigusr1;	/* SIGUSR1 */
1040Sstevel@tonic-gate struct	sigaction	Sigusr2;	/* SIGUSR2 */
1050Sstevel@tonic-gate #endif
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate struct strbuf *peek_ptr;
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate int Logmaxsz = 1000000; /* Log Max Size */
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate int Splflag = 0; /* serialize Log file manipulation */
112