| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#ifndef _USUAL_SIGNAL_H_ |
| 28 |
#define _USUAL_SIGNAL_H_ |
| 29 |
|
| 30 |
#include <usual/base.h> |
| 31 |
|
| 32 |
#include <signal.h> |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
#if !defined(SI_QUEUE) && !defined(HAVE_SIGQUEUE) |
| 39 |
union sigval { |
| 40 |
int sival_int; |
| 41 |
void *sival_ptr; |
| 42 |
}; |
| 43 |
#endif |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
#ifndef SIGEV_NONE |
| 50 |
#define SIGEV_NONE 0 |
| 51 |
#define SIGEV_SIGNAL 1 |
| 52 |
#define SIGEV_THREAD 2 |
| 53 |
struct sigevent { |
| 54 |
int sigev_notify; |
| 55 |
int sigev_signo; |
| 56 |
union sigval sigev_value; |
| 57 |
void (*sigev_notify_function)(union sigval); |
| 58 |
|
| 59 |
}; |
| 60 |
#endif |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
#ifndef HAVE_SIGACTION |
| 67 |
#define SA_SIGINFO 1 |
| 68 |
#define SA_RESTART 2 |
| 69 |
typedef struct siginfo_t siginfo_t; |
| 70 |
struct sigaction { |
| 71 |
union { |
| 72 |
void (*sa_handler)(int); |
| 73 |
void (*sa_sigaction)(int, siginfo_t *, void *); |
| 74 |
}; |
| 75 |
int sa_flags; |
| 76 |
int sa_mask; |
| 77 |
}; |
| 78 |
#define sigemptyset(s) |
| 79 |
#define sigfillset(s) |
| 80 |
#define sigaddset(s, sig) |
| 81 |
#define sigdelset(s, sig) |
| 82 |
#define sigaction(a,b,c) compat_sigaction(a,b,c) |
| 83 |
int sigaction(int sig, const struct sigaction *sa, struct sigaction *old); |
| 84 |
#endif |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
#ifdef WIN32 |
| 92 |
|
| 93 |
#define SIGALRM 1023 |
| 94 |
#define SIGBUS 1022 |
| 95 |
unsigned alarm(unsigned); |
| 96 |
|
| 97 |
int kill(int pid, int sig); |
| 98 |
|
| 99 |
typedef void (*_sighandler_t)(int); |
| 100 |
|
| 101 |
static inline _sighandler_t wrap_signal(int sig, _sighandler_t func) |
| 102 |
{ |
| 103 |
|
| 104 |
if (sig == SIGALRM) { |
| 105 |
struct sigaction sa, oldsa; |
| 106 |
sa.sa_handler = func; |
| 107 |
sa.sa_flags = sa.sa_mask = 0; |
| 108 |
sigaction(SIGALRM, &sa, &oldsa); |
| 109 |
return oldsa.sa_handler; |
| 110 |
} else if (sig == SIGBUS) { |
| 111 |
return NULL; |
| 112 |
} |
| 113 |
return signal(sig, func); |
| 114 |
} |
| 115 |
#define signal(a,b) wrap_signal(a,b) |
| 116 |
#endif |
| 117 |
|
| 118 |
#endif |