source: libcfa/src/bits/signal.hfa @ 1b56a7f

Last change on this file since 1b56a7f was b08ab18, checked in by Peter A. Buhr <pabuhr@…>, 9 months ago

formatting

  • Property mode set to 100644
File size: 1.7 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// bits/signal.hfa -- Helper functions and defines to use signals
8//
9// Author           : Thierry Delisle
10// Created On       : Thu Jan 25 16:06:29 2018
11// Last Modified By :
12// Last Modified On :
13// Update Count     :
14//
15
16#pragma once
17
18#include "bits/debug.hfa"
19#include "bits/defs.hfa"
20
21#include <errno.h>
22#include <signal.h>
23#include <stdlib.h>
24#include <string.h>
25
26// Short hands for signal context information
27#define __CFA_SIGCXT__ ucontext_t *
28#define __CFA_SIGPARMS__ __attribute__((unused)) int sig, __attribute__((unused)) siginfo_t *sfp, __attribute__((unused)) __CFA_SIGCXT__ cxt
29
30// Sigaction wrapper : register an signal handler
31static void __cfaabi_sigaction( int sig, void (*handler)(__CFA_SIGPARMS__), int flags ) {
32        struct sigaction act;
33
34        act.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler;
35        sigemptyset( &act.sa_mask );
36        sigaddset( &act.sa_mask, SIGALRM );                                     // disabled during signal handler
37        sigaddset( &act.sa_mask, SIGUSR1 );
38        sigaddset( &act.sa_mask, SIGSEGV );
39        sigaddset( &act.sa_mask, SIGBUS );
40        sigaddset( &act.sa_mask, SIGILL );
41        sigaddset( &act.sa_mask, SIGFPE );
42        sigaddset( &act.sa_mask, SIGHUP );                                      // revert to default on second delivery
43        sigaddset( &act.sa_mask, SIGTERM );
44        sigaddset( &act.sa_mask, SIGINT );
45        act.sa_flags = flags;
46
47        if ( sigaction( sig, &act, 0p ) == -1 ) {
48                __cfaabi_dbg_print_buffer_decl(
49                        " __cfaabi_sigaction( sig:%d, handler:%p, flags:%d ), problem installing signal handler, error(%d) %s.\n",
50                        sig, handler, flags, errno, strerror( errno )
51                );
52                _Exit( EXIT_FAILURE );
53        } // if
54}
Note: See TracBrowser for help on using the repository browser.