1
- /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
2
- │ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
3
- ╞══════════════════════════════════════════════════════════════════════════════╡
4
- │ Copyright 2023 Justine Alexandra Roberts Tunney │
5
- │ │
6
- │ Permission to use, copy, modify, and/or distribute this software for │
7
- │ any purpose with or without fee is hereby granted, provided that the │
8
- │ above copyright notice and this permission notice appear in all copies. │
9
- │ │
10
- │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
11
- │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
12
- │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
13
- │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
14
- │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
15
- │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
16
- │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
17
- │ PERFORMANCE OF THIS SOFTWARE. │
18
- ╚─────────────────────────────────────────────────────────────────────────────*/
19
- #include "libc/calls/calls.h"
20
- #include "libc/calls/struct/sigaction.h"
21
- #include "libc/calls/struct/sigset.h"
22
- #include "libc/dce.h"
23
- #include "libc/sysv/consts/sa.h"
24
- #include "libc/sysv/consts/sig.h"
1
+ // Copyright 2024 Justine Alexandra Roberts Tunney
2
+ //
3
+ // Permission to use, copy, modify, and/or distribute this software for
4
+ // any purpose with or without fee is hereby granted, provided that the
5
+ // above copyright notice and this permission notice appear in all copies.
6
+ //
7
+ // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
8
+ // WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
9
+ // WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
10
+ // AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
11
+ // DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
12
+ // PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
13
+ // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
+ // PERFORMANCE OF THIS SOFTWARE.
15
+
16
+ #include <signal.h>
17
+ #include <unistd.h>
25
18
26
19
volatile int handler_invoked ;
27
20
@@ -33,24 +26,17 @@ int main() {
33
26
sigset_t mask , oldmask ;
34
27
struct sigaction sa , current_sa ;
35
28
36
- if (IsWindows ()) {
37
- // TODO(jart): support non-fatal signals between processes
38
- return 0 ;
39
- }
40
-
41
29
sa .sa_handler = signal_handler ;
42
30
sa .sa_flags = SA_RESETHAND ;
43
31
sigemptyset (& sa .sa_mask );
44
32
45
- if (sigaction (SIGINT , & sa , 0 ) == -1 ) {
33
+ if (sigaction (SIGINT , & sa , 0 ) == -1 )
46
34
return 1 ;
47
- }
48
35
49
36
sigemptyset (& mask );
50
37
sigaddset (& mask , SIGINT );
51
- if (sigprocmask (SIG_BLOCK , & mask , & oldmask ) == -1 ) {
38
+ if (sigprocmask (SIG_BLOCK , & mask , & oldmask ) == -1 )
52
39
return 2 ;
53
- }
54
40
55
41
int pid = fork ();
56
42
if (pid == -1 ) {
@@ -60,15 +46,12 @@ int main() {
60
46
return 0 ;
61
47
} else {
62
48
sigsuspend (& oldmask );
63
- if (!handler_invoked ) {
49
+ if (!handler_invoked )
64
50
return 4 ;
65
- }
66
- if (sigaction (SIGINT , 0 , & current_sa ) == -1 ) {
51
+ if (sigaction (SIGINT , 0 , & current_sa ) == -1 )
67
52
return 5 ;
68
- }
69
- if (current_sa .sa_handler != SIG_DFL ) {
53
+ if (current_sa .sa_handler != SIG_DFL )
70
54
return 6 ;
71
- }
72
55
return 0 ;
73
56
}
74
57
}
0 commit comments