xref: /netbsd-src/external/bsd/openldap/dist/libraries/liblutil/signal.c (revision 181254a7b1bdde6873432bffef2d2decc4b5c22f)
1 /*	$NetBSD: signal.c,v 1.2 2020/08/11 13:15:39 christos Exp $	*/
2 
3 /* $OpenLDAP$ */
4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5  *
6  * Copyright 1998-2020 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 <sys/cdefs.h>
19 __RCSID("$NetBSD: signal.c,v 1.2 2020/08/11 13:15:39 christos Exp $");
20 
21 #include "portable.h"
22 
23 #ifdef HAVE_SIGACTION
24 #include <ac/string.h>
25 #include <ac/signal.h>
26 
27 lutil_sig_t
28 lutil_sigaction(int sig, lutil_sig_t func)
29 {
30 	struct sigaction action, oaction;
31 
32 	memset( &action, '\0', sizeof(action) );
33 
34 	action.sa_handler = func;
35 	sigemptyset( &action.sa_mask );
36 #ifdef SA_RESTART
37 	action.sa_flags |= SA_RESTART;
38 #endif
39 
40 	if( sigaction( sig, &action, &oaction ) != 0 ) {
41 		return NULL;
42 	}
43 
44 	return oaction.sa_handler;
45 }
46 #endif
47