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