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/param.h> 32 #include <sys/resource.h> 33 #include <sac.h> 34 #include "tmstruct.h" 35 #include "ttymon.h" 36 37 /* 38 * global fd and fp 39 */ 40 FILE *Logfp = NULL; /* for log file */ 41 int Lckfd; /* for pid file */ 42 int Sfd, Pfd; /* for sacpipe and pmpipe */ 43 int PCpipe[2]; /* pipe between Parent & Children */ 44 #ifdef DEBUG 45 FILE *Debugfp = NULL; /* for debug file */ 46 #endif 47 48 char State = PM_STARTING; /* current state */ 49 char *Istate; /* initial state */ 50 char *Tag; /* port monitor tag */ 51 int Maxfiles; /* Max number of open files */ 52 int Maxfds; /* Max no of devices ttymon can monitor */ 53 54 int Reread_flag = FALSE; /* reread pmtab flag */ 55 56 int Retry; /* retry open_device flag */ 57 58 struct pmtab *PMtab = NULL; /* head pointer to pmtab linked list */ 59 int Nentries = 0; /* # of entries in pmtab linked list */ 60 61 struct Gdef Gdef[MAXDEFS]; /* array to hold entries in /etc/ttydefs */ 62 int Ndefs = 0; /* highest index to Gdef that was used */ 63 long Mtime = 0; /* last modification time of ttydefs */ 64 65 struct pollfd *Pollp; /* ptr to an array of poll struct */ 66 int Npollfd; /* size of the pollfd array */ 67 68 struct Gdef DEFAULT = { /* default terminal settings */ 69 "default", 70 "9600", 71 "9600 sane", 72 0, 73 /* 74 * next label is set to 4800 so we can start searching ttydefs. 75 * if 4800 is not in ttydefs, we will loop back to use DEFAULT 76 */ 77 "4800" 78 }; 79 80 uid_t Uucp_uid = 5; /* owner's uid for bi-directional ports */ 81 gid_t Tty_gid = GID_TTY; /* group id for all tty devices */ 82 83 /* 84 * Nlocked - number of ports that are either locked or have active 85 * sessions not under this ttymon. 86 */ 87 int Nlocked = 0; 88 89 /* original rlimit value */ 90 struct rlimit Rlimit; 91 92 /* 93 * places to remember original signal dispositions and masks 94 */ 95 96 sigset_t Origmask; /* original signal mask */ 97 struct sigaction Sigalrm; /* SIGALRM */ 98 struct sigaction Sigcld; /* SIGCLD */ 99 struct sigaction Sigint; /* SIGINT */ 100 struct sigaction Sigpoll; /* SIGPOLL */ 101 struct sigaction Sigquit; /* SIGQUIT */ 102 struct sigaction Sigterm; /* SIGTERM */ 103 #ifdef DEBUG 104 struct sigaction Sigusr1; /* SIGUSR1 */ 105 struct sigaction Sigusr2; /* SIGUSR2 */ 106 #endif 107 108 struct strbuf *peek_ptr; 109 110 int Logmaxsz = 1000000; /* Log Max Size */ 111 112 int Splflag = 0; /* serialize Log file manipulation */ 113