Evita  0.16
evSignal.h
Go to the documentation of this file.
1 /*
2  *
3  * EVITA: Efficient Visualization of Terascale Datasets
4  * Copyright (C) 2000-2016 Team Evita
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
19  * MA 02139, USA.
20  *
21  */
22 
23 
24 #ifndef __evSignal_h
25 #define __evSignal_h
26 
27 
28 #include "evConfig.h"
29 
30 #include <unistd.h>
31 #include <signal.h>
32 #include <sys/wait.h>
33 #include <errno.h>
34 #include <sys/types.h>
35 
36 
37 #define EVSIGNAL_DISCONNECT (SIGRTMIN)
38 #define EVSIGNAL_CLOSE (SIGRTMIN + 1)
39 #define EVSIGNAL_QUIT (SIGRTMIN + 2)
40 
41 typedef void evSignalHandler(int);
42 
43 
44 inline int evSignalBlock(const int signal)
45 {
46  sigset_t set;
47 
48  sigemptyset(&set);
49  sigaddset(&set, signal);
50 
51  return(pthread_sigmask(SIG_BLOCK, &set, NULL) != 0);
52 }
53 
54 
55 inline int evSignalUnblock(const int signal)
56 {
57  sigset_t set;
58 
59  sigemptyset(&set);
60  sigaddset(&set, signal);
61 
62  return(pthread_sigmask(SIG_UNBLOCK, &set, NULL) != 0);
63 }
64 
65 
66 inline int evSignalSetHandler(const int signal,
67  evSignalHandler signal_handler)
68 {
69  struct sigaction action, old_action;
70 
71  action.sa_handler = signal_handler;
72  sigemptyset(&action.sa_mask);
73  action.sa_flags = 0;
74 #ifdef SA_INTERRUPT
75  action.sa_flags |= SA_INTERRUPT;
76 #endif
77  return(sigaction(signal, &action, &old_action) != 0);
78 }
79 
80 
81 inline int evSignalSend(const int signal)
82 {
83  return(kill(0, signal) != 0);
84 }
85 
86 
87 inline int evSignalWait(void)
88 {
89  sigset_t signal_set;
90 
91  sigfillset(&signal_set);
92 
93  int signal;
94  sigwait(&signal_set, &signal);
95 
96  return(signal);
97 }
98 
99 
100 inline void evSignalStartSession(void)
101 {
102  setsid();
103 }
104 
105 
106 #endif
int evSignalBlock(const int signal)
Definition: evSignal.h:44
void evSignalStartSession(void)
Definition: evSignal.h:100
int evSignalSetHandler(const int signal, evSignalHandler signal_handler)
Definition: evSignal.h:66
void evSignalHandler(int)
Definition: evSignal.h:41
int evSignalSend(const int signal)
Definition: evSignal.h:81
int evSignalWait(void)
Definition: evSignal.h:87
int evSignalUnblock(const int signal)
Definition: evSignal.h:55