xref: /titanic_52/usr/src/cmd/ttymon/tmsig.c (revision 7fd791373689a6af05e27efec3b1ab556e02aa23)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27 /*	  All Rights Reserved  	*/
28 
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include	<stdio.h>
33 #include	<signal.h>
34 #include	"tmextern.h"
35 
36 /*
37  * catch_signals:
38  *	ttymon catch some signals and ignore the rest.
39  *
40  *	SIGTERM	- killed by somebody
41  *	SIGPOLL - got message on pmpipe, probably from sac
42  *			   or on PCpipe
43  *	SIGCLD	- tmchild died
44  */
45 void
46 catch_signals()
47 {
48 	sigset_t cset;
49 	struct sigaction sigact;
50 	extern void sigterm();
51 	extern void sigchild();
52 	extern void sigpoll_catch();
53 #ifdef	DEBUG
54 	extern void dump_pmtab();
55 	extern void dump_ttydefs();
56 
57 	debug("in catch_signals");
58 #endif
59 
60 	cset = Origmask;
61 	(void)sigdelset(&cset, SIGTERM);
62 	(void)sigdelset(&cset, SIGCLD);
63 	(void)sigdelset(&cset, SIGPOLL);
64 #ifdef	DEBUG
65 	(void)sigdelset(&cset, SIGUSR1);
66 	(void)sigdelset(&cset, SIGUSR2);
67 #endif
68 	(void)sigprocmask(SIG_SETMASK, &cset, NULL);
69 	sigact.sa_flags = 0;
70 	sigact.sa_handler = sigterm;
71 	(void)sigemptyset(&sigact.sa_mask);
72 	(void)sigaddset(&sigact.sa_mask, SIGTERM);
73 	(void)sigaction(SIGTERM, &sigact, NULL);
74 	sigact.sa_flags = 0;
75 	sigact.sa_handler = sigchild;
76 	(void)sigemptyset(&sigact.sa_mask);
77 	(void)sigaction(SIGCLD, &sigact, NULL);
78 	sigact.sa_flags = 0;
79 	sigact.sa_handler = sigpoll_catch;
80 	(void)sigemptyset(&sigact.sa_mask);
81 	(void)sigaddset(&sigact.sa_mask, SIGPOLL);
82 	(void)sigaction(SIGPOLL, &sigact, NULL);
83 #ifdef	DEBUG
84 	sigact.sa_flags = 0;
85 	sigact.sa_handler = dump_pmtab;
86 	(void)sigemptyset(&sigact.sa_mask);
87 	(void)sigaddset(&sigact.sa_mask, SIGUSR1);
88 	(void)sigaction(SIGUSR1, &sigact, NULL);
89 	sigact.sa_flags = 0;
90 	sigact.sa_handler = dump_ttydefs;
91 	(void)sigemptyset(&sigact.sa_mask);
92 	(void)sigaddset(&sigact.sa_mask, SIGUSR2);
93 	(void)sigaction(SIGUSR2, &sigact, NULL);
94 #endif
95 }
96 
97 /*
98  * child_sigcatch() - tmchild inherits some signal_catch from parent
99  *		      and need to reset them
100  */
101 void
102 child_sigcatch()
103 {
104 	struct	sigaction	sigact;
105 	sigset_t cset;
106 	extern	void	sigpoll();
107 	extern	void	sigint();
108 
109 	cset = Origmask;
110 	(void)sigdelset(&cset, SIGINT);
111 	(void)sigdelset(&cset, SIGPOLL);
112 	(void)sigprocmask(SIG_SETMASK, &cset, NULL);
113 	sigact.sa_flags = 0;
114 	sigact.sa_handler = sigpoll;
115 	(void)sigemptyset(&sigact.sa_mask);
116 	(void)sigaddset(&sigact.sa_mask, SIGPOLL);
117 	(void)sigaction(SIGPOLL, &sigact, NULL);
118 	sigact.sa_flags = 0;
119 	sigact.sa_handler = sigint;
120 	(void)sigemptyset(&sigact.sa_mask);
121 	(void)sigaddset(&sigact.sa_mask, SIGINT);
122 	(void)sigaction(SIGINT, &sigact, NULL);
123 }
124