Back to index

openldap  2.4.31
signal.c
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 1998-2012 The OpenLDAP Foundation.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted only as authorized by the OpenLDAP
00009  * Public License.
00010  *
00011  * A copy of this license is available in the file LICENSE in the
00012  * top-level directory of the distribution or, alternatively, at
00013  * <http://www.OpenLDAP.org/license.html>.
00014  */
00015 
00016 #include "portable.h"
00017 
00018 #ifdef HAVE_SIGACTION
00019 #include <ac/string.h>
00020 #include <ac/signal.h>
00021 
00022 lutil_sig_t
00023 lutil_sigaction(int sig, lutil_sig_t func)
00024 {
00025        struct sigaction action, oaction;
00026 
00027        memset( &action, '\0', sizeof(action) );
00028 
00029        action.sa_handler = func;
00030        sigemptyset( &action.sa_mask );
00031 #ifdef SA_RESTART
00032        action.sa_flags |= SA_RESTART;
00033 #endif
00034        
00035        if( sigaction( sig, &action, &oaction ) != 0 ) {
00036               return NULL;
00037        }
00038 
00039        return oaction.sa_handler;
00040 }
00041 #endif