xref: /illumos-gate/usr/src/cmd/make/lib/bsd/bsd.cc (revision 14843420)
110d63b7dSRichard Lowe /*
210d63b7dSRichard Lowe  * CDDL HEADER START
310d63b7dSRichard Lowe  *
410d63b7dSRichard Lowe  * The contents of this file are subject to the terms of the
510d63b7dSRichard Lowe  * Common Development and Distribution License (the "License").
610d63b7dSRichard Lowe  * You may not use this file except in compliance with the License.
710d63b7dSRichard Lowe  *
810d63b7dSRichard Lowe  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
910d63b7dSRichard Lowe  * or http://www.opensolaris.org/os/licensing.
1010d63b7dSRichard Lowe  * See the License for the specific language governing permissions
1110d63b7dSRichard Lowe  * and limitations under the License.
1210d63b7dSRichard Lowe  *
1310d63b7dSRichard Lowe  * When distributing Covered Code, include this CDDL HEADER in each
1410d63b7dSRichard Lowe  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1510d63b7dSRichard Lowe  * If applicable, add the following below this CDDL HEADER, with the
1610d63b7dSRichard Lowe  * fields enclosed by brackets "[]" replaced with your own identifying
1710d63b7dSRichard Lowe  * information: Portions Copyright [yyyy] [name of copyright owner]
1810d63b7dSRichard Lowe  *
1910d63b7dSRichard Lowe  * CDDL HEADER END
2010d63b7dSRichard Lowe  */
2110d63b7dSRichard Lowe /*
2210d63b7dSRichard Lowe  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
2310d63b7dSRichard Lowe  * Use is subject to license terms.
2410d63b7dSRichard Lowe  */
2510d63b7dSRichard Lowe 
2610d63b7dSRichard Lowe 
2710d63b7dSRichard Lowe #include <signal.h>
2810d63b7dSRichard Lowe 
2910d63b7dSRichard Lowe #include <bsd/bsd.h>
3010d63b7dSRichard Lowe 
3110d63b7dSRichard Lowe /* External references.
3210d63b7dSRichard Lowe  */
3310d63b7dSRichard Lowe 
3410d63b7dSRichard Lowe /* Forward references.
3510d63b7dSRichard Lowe  */
3610d63b7dSRichard Lowe 
3710d63b7dSRichard Lowe /* Static data.
3810d63b7dSRichard Lowe  */
3910d63b7dSRichard Lowe 
4010d63b7dSRichard Lowe extern SIG_PF
bsd_signal(int Signal,SIG_PF Handler)4110d63b7dSRichard Lowe bsd_signal (int Signal, SIG_PF Handler)
4210d63b7dSRichard Lowe {
43*14843420SToomas Soome   SIG_PF                   previous_handler;
4410d63b7dSRichard Lowe #ifdef sun
4510d63b7dSRichard Lowe   previous_handler = sigset (Signal, Handler);
4610d63b7dSRichard Lowe #else
47*14843420SToomas Soome   struct sigaction         new_action;
48*14843420SToomas Soome   struct sigaction         old_action;
4910d63b7dSRichard Lowe 
5010d63b7dSRichard Lowe   new_action.sa_flags = SA_SIGINFO;
5110d63b7dSRichard Lowe   new_action.sa_handler = (void (*) ()) Handler;
5210d63b7dSRichard Lowe   (void) sigemptyset (&new_action.sa_mask);
5310d63b7dSRichard Lowe   (void) sigaddset (&new_action.sa_mask, Signal);
5410d63b7dSRichard Lowe 
5510d63b7dSRichard Lowe   (void) sigaction (Signal, &new_action, &old_action);
5610d63b7dSRichard Lowe 
5710d63b7dSRichard Lowe   previous_handler = (SIG_PF) old_action.sa_handler;
5810d63b7dSRichard Lowe #endif
5910d63b7dSRichard Lowe   return previous_handler;
6010d63b7dSRichard Lowe }
6110d63b7dSRichard Lowe 
6210d63b7dSRichard Lowe extern void
bsd_signals(void)6310d63b7dSRichard Lowe bsd_signals (void)
6410d63b7dSRichard Lowe {
6510d63b7dSRichard Lowe   static int                    initialized = 0;
6610d63b7dSRichard Lowe 
6710d63b7dSRichard Lowe   if (initialized == 0)
6810d63b7dSRichard Lowe     {
6910d63b7dSRichard Lowe       initialized = 1;
7010d63b7dSRichard Lowe     }
7110d63b7dSRichard Lowe 
7210d63b7dSRichard Lowe   return;
7310d63b7dSRichard Lowe }
74