xref: /illumos-gate/usr/src/cmd/ttymon/tmsig.c (revision 3bb2c156)
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 #include	<stdio.h>
30 #include	<signal.h>
31 #include	"tmextern.h"
32 
33 /*
34  * catch_signals:
35  *	ttymon catch some signals and ignore the rest.
36  *
37  *	SIGTERM	- killed by somebody
38  *	SIGPOLL - got message on pmpipe, probably from sac
39  *			   or on PCpipe
40  *	SIGCLD	- tmchild died
41  */
42 void
catch_signals(void)43 catch_signals(void)
44 {
45 	sigset_t cset;
46 	struct sigaction sigact;
47 
48 #ifdef	DEBUG
49 	debug("in catch_signals");
50 #endif
51 
52 	cset = Origmask;
53 	(void) sigdelset(&cset, SIGTERM);
54 	(void) sigdelset(&cset, SIGCLD);
55 	(void) sigdelset(&cset, SIGPOLL);
56 #ifdef	DEBUG
57 	(void) sigdelset(&cset, SIGUSR1);
58 	(void) sigdelset(&cset, SIGUSR2);
59 #endif
60 	(void) sigprocmask(SIG_SETMASK, &cset, NULL);
61 	sigact.sa_flags = 0;
62 	sigact.sa_handler = sigterm;
63 	(void) sigemptyset(&sigact.sa_mask);
64 	(void) sigaddset(&sigact.sa_mask, SIGTERM);
65 	(void) sigaction(SIGTERM, &sigact, NULL);
66 	sigact.sa_flags = 0;
67 	sigact.sa_handler = sigchild;
68 	(void) sigemptyset(&sigact.sa_mask);
69 	(void) sigaction(SIGCLD, &sigact, NULL);
70 	sigact.sa_flags = 0;
71 	sigact.sa_handler = sigpoll_catch;
72 	(void) sigemptyset(&sigact.sa_mask);
73 	(void) sigaddset(&sigact.sa_mask, SIGPOLL);
74 	(void) sigaction(SIGPOLL, &sigact, NULL);
75 #ifdef	DEBUG
76 	sigact.sa_flags = 0;
77 	sigact.sa_handler = dump_pmtab;
78 	(void) sigemptyset(&sigact.sa_mask);
79 	(void) sigaddset(&sigact.sa_mask, SIGUSR1);
80 	(void) sigaction(SIGUSR1, &sigact, NULL);
81 	sigact.sa_flags = 0;
82 	sigact.sa_handler = dump_ttydefs;
83 	(void) sigemptyset(&sigact.sa_mask);
84 	(void) sigaddset(&sigact.sa_mask, SIGUSR2);
85 	(void) sigaction(SIGUSR2, &sigact, NULL);
86 #endif
87 }
88 
89 /*
90  * child_sigcatch() - tmchild inherits some signal_catch from parent
91  *		      and need to reset them
92  */
93 void
child_sigcatch(void)94 child_sigcatch(void)
95 {
96 	struct	sigaction	sigact;
97 	sigset_t cset;
98 
99 	cset = Origmask;
100 	(void) sigdelset(&cset, SIGINT);
101 	(void) sigdelset(&cset, SIGPOLL);
102 	(void) sigprocmask(SIG_SETMASK, &cset, NULL);
103 	sigact.sa_flags = 0;
104 	sigact.sa_handler = sigpoll;
105 	(void) sigemptyset(&sigact.sa_mask);
106 	(void) sigaddset(&sigact.sa_mask, SIGPOLL);
107 	(void) sigaction(SIGPOLL, &sigact, NULL);
108 	sigact.sa_flags = 0;
109 	sigact.sa_handler = sigint;
110 	(void) sigemptyset(&sigact.sa_mask);
111 	(void) sigaddset(&sigact.sa_mask, SIGINT);
112 	(void) sigaction(SIGINT, &sigact, NULL);
113 }
114