xref: /netbsd-src/external/bsd/openldap/dist/libraries/liblutil/signal.c (revision 6cf6fe02a981b55727c49c3d37b0d8191a98c0ee)
1 /*	$NetBSD: signal.c,v 1.1.1.4 2014/05/28 09:58:45 tron Exp $	*/
2 
3 /* $OpenLDAP$ */
4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5  *
6  * Copyright 1998-2014 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