xref: /illumos-gate/usr/src/cmd/ttymon/tmglobal.c (revision 0250c53ad267726f2438e3c6556199a0bbf588a2)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
26 /*	  All Rights Reserved  	*/
27 
28 #include <stdio.h>
29 #include <poll.h>
30 #include <signal.h>
31 #include <sys/resource.h>
32 #include <sac.h>
33 #include "tmstruct.h"
34 #include "ttymon.h"
35 
36 /*
37  *	global fd and fp
38  */
39 FILE	*Logfp = NULL;		/* for log file			*/
40 int	Lckfd;			/* for pid file			*/
41 int	Sfd, Pfd;		/* for sacpipe and pmpipe 	*/
42 int	PCpipe[2];		/* pipe between Parent & Children */
43 #ifdef	DEBUG
44 FILE	*Debugfp = NULL;	/* for debug file		*/
45 #endif
46 
47 char	State = PM_STARTING;	/* current state			*/
48 char	*Istate;		/* initial state			*/
49 char	*Tag;			/* port monitor tag			*/
50 int	Maxfiles;		/* Max number of open files		*/
51 int	Maxfds;			/* Max no of devices ttymon can monitor */
52 
53 int	Reread_flag = FALSE;	/* reread pmtab flag			*/
54 
55 int	Retry;			/* retry open_device flag		*/
56 
57 struct  pmtab *PMtab = NULL;	/* head pointer to pmtab linked list 	*/
58 int	Nentries = 0;		/* # of entries in pmtab linked list	*/
59 
60 struct  Gdef Gdef[MAXDEFS];	/* array to hold entries in /etc/ttydefs */
61 int	Ndefs = 0;		/* highest index to Gdef that was used   */
62 long	Mtime = 0;		/* last modification time of ttydefs	 */
63 
64 struct pollfd *Pollp;		/* ptr to an array of poll struct	*/
65 int	Npollfd;		/* size of the pollfd array		 */
66 
67 struct Gdef DEFAULT = {		/* default terminal settings	*/
68 	"default",
69 	"9600",
70 	"9600 sane",
71 	0,
72 	/*
73 	 * next label is set to 4800 so we can start searching ttydefs.
74 	 * if 4800 is not in ttydefs, we will loop back to use DEFAULT
75 	 */
76 	"4800"
77 };
78 
79 uid_t	Uucp_uid = 5;		/* owner's uid for bi-directional ports	*/
80 gid_t	Tty_gid = 7;		/* group id for all tty devices		*/
81 
82 /*
83  * Nlocked - 	number of ports that are either locked or have active
84  *		sessions not under this ttymon.
85  */
86 int	Nlocked = 0;
87 
88 /* original rlimit value */
89 struct	rlimit	Rlimit;
90 
91 /*
92  * places to remember original signal dispositions and masks
93  */
94 
95 sigset_t	Origmask;		/* original signal mask */
96 struct	sigaction	Sigalrm;	/* SIGALRM */
97 struct	sigaction	Sigcld;		/* SIGCLD */
98 struct	sigaction	Sigint;		/* SIGINT */
99 struct	sigaction	Sigpoll;	/* SIGPOLL */
100 struct	sigaction	Sigquit;	/* SIGQUIT */
101 struct	sigaction	Sigterm;	/* SIGTERM */
102 #ifdef	DEBUG
103 struct	sigaction	Sigusr1;	/* SIGUSR1 */
104 struct	sigaction	Sigusr2;	/* SIGUSR2 */
105 #endif
106 
107 struct strbuf *peek_ptr;
108 
109 int Logmaxsz = 1000000; /* Log Max Size */
110 
111 int Splflag = 0; /* serialize Log file manipulation */
112