Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libast/misc/signal.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1985-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* David Korn <[email protected]> *
19
* Phong Vo <[email protected]> *
20
* *
21
***********************************************************************/
22
#pragma prototyped
23
24
/*
25
* signal that disables syscall restart on interrupt with clear signal mask
26
* fun==SIG_DFL also unblocks signal
27
*/
28
29
#if !_UWIN
30
31
#undef signal
32
#define signal ______signal
33
34
#endif
35
36
#include <ast.h>
37
#include <sig.h>
38
39
#if !_UWIN
40
41
#undef signal
42
43
#undef _def_map_ast
44
#include <ast_map.h>
45
46
#if defined(__EXPORT__)
47
#define extern __EXPORT__
48
#endif
49
50
#endif
51
52
#if defined(SV_ABORT)
53
#undef SV_INTERRUPT
54
#define SV_INTERRUPT SV_ABORT
55
#endif
56
57
#if !_std_signal && (_lib_sigaction && defined(SA_NOCLDSTOP) || _lib_sigvec && defined(SV_INTERRUPT))
58
59
#if !defined(SA_NOCLDSTOP) || !defined(SA_INTERRUPT) && defined(SV_INTERRUPT)
60
#undef SA_INTERRUPT
61
#define SA_INTERRUPT SV_INTERRUPT
62
#undef sigaction
63
#define sigaction sigvec
64
#undef sigemptyset
65
#define sigemptyset(p) (*(p)=0)
66
#undef sa_flags
67
#define sa_flags sv_flags
68
#undef sa_handler
69
#define sa_handler sv_handler
70
#undef sa_mask
71
#define sa_mask sv_mask
72
#endif
73
74
extern Sig_handler_t
75
signal(int sig, Sig_handler_t fun)
76
{
77
struct sigaction na;
78
struct sigaction oa;
79
int unblock;
80
#ifdef SIGNO_MASK
81
unsigned int flags;
82
#endif
83
84
if (sig < 0)
85
{
86
sig = -sig;
87
unblock = 0;
88
}
89
else
90
unblock = fun == SIG_DFL;
91
#ifdef SIGNO_MASK
92
flags = sig & ~SIGNO_MASK;
93
sig &= SIGNO_MASK;
94
#endif
95
memzero(&na, sizeof(na));
96
na.sa_handler = fun;
97
#if defined(SA_INTERRUPT) || defined(SA_RESTART)
98
switch (sig)
99
{
100
#if defined(SIGIO) || defined(SIGTSTP) || defined(SIGTTIN) || defined(SIGTTOU)
101
#if defined(SIGIO)
102
case SIGIO:
103
#endif
104
#if defined(SIGTSTP)
105
case SIGTSTP:
106
#endif
107
#if defined(SIGTTIN)
108
case SIGTTIN:
109
#endif
110
#if defined(SIGTTOU)
111
case SIGTTOU:
112
#endif
113
#if defined(SA_RESTART)
114
na.sa_flags = SA_RESTART;
115
#endif
116
break;
117
#endif
118
default:
119
#if defined(SA_INTERRUPT)
120
na.sa_flags = SA_INTERRUPT;
121
#endif
122
break;
123
}
124
#endif
125
if (sigaction(sig, &na, &oa))
126
return 0;
127
if (unblock)
128
sigunblock(sig);
129
return oa.sa_handler;
130
}
131
132
#else
133
134
NoN(signal)
135
136
#endif
137
138