1 /*	$NetBSD: signal.c,v 1.1.1.3 2010/12/12 15:22:11 adam Exp $	*/
2 
3 /* OpenLDAP: pkg/ldap/libraries/liblutil/signal.c,v 1.10.2.5 2010/04/13 20:23:07 kurt Exp */
4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5  *
6  * Copyright 1998-2010 The OpenLDAP Foundation.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in the file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 
18 #include "portable.h"
19 
20 #ifdef HAVE_SIGACTION
21 #include <ac/string.h>
22 #include <ac/signal.h>
23 
24 lutil_sig_t
25 lutil_sigaction(int sig, lutil_sig_t func)
26 {
27 	struct sigaction action, oaction;
28 
29 	memset( &action, '\0', sizeof(action) );
30 
31 	action.sa_handler = func;
32 	sigemptyset( &action.sa_mask );
33 #ifdef SA_RESTART
34 	action.sa_flags |= SA_RESTART;
35 #endif
36 
37 	if( sigaction( sig, &action, &oaction ) != 0 ) {
38 		return NULL;
39 	}
40 
41 	return oaction.sa_handler;
42 }
43 #endif
44