Datasets:

License:
File size: 2,967 Bytes
3dcad1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
exec guile -q -s "$0" "$@"
!#
;;; test-sigaction-fork --- Signal thread vs. fork, again.
;;;
;;; Copyright (C) 2024 Free Software Foundation, Inc.
;;;
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Lesser General Public
;;; License as published by the Free Software Foundation; either
;;; version 3 of the License, or (at your option) any later version.
;;;
;;; This library is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;; Lesser General Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public
;;; License along with this library; if not, write to the Free Software
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

;;; Test the bug described at <https://bugs.gnu.org/68087>: the signal
;;; thread would not be restarted after a call to 'primitive-fork',
;;; leading signals to be silently ignored.

(use-modules (ice-9 match))

(define signals-handled
  ;; List of signals handled.
  '())

(define parent
  ;; PID of the parent process.
  (getpid))

(unless (provided? 'fork)
  (exit 77))

;; This call spawns the signal delivery thread as a side effect.
(sigaction SIGALRM
  (lambda (signal)
    (call-with-blocked-asyncs
     (lambda ()
       (set! signals-handled
             (cons `(first-handler . ,(getpid))
                   signals-handled))))))

(kill (getpid) SIGALRM)
(while (null? signals-handled)                    ;let the async run
  (sleep 1))

(match (primitive-fork)
  (0
   (pk 'child (getpid) signals-handled)
   (kill (getpid) SIGALRM)                        ;first handler
   (sleep 1)                                      ;let the async run
   (sigaction SIGALRM
     (lambda (signal)
       (call-with-blocked-asyncs
        (lambda ()
          (set! signals-handled
                (cons `(second-handler . ,(getpid))
                      signals-handled))))))
   (kill (getpid) SIGALRM)           ;second handler
   (sleep 1)                         ;give asyncs one more chance to run
   (format (current-error-port) "signals handled by the child + parent: ~s~%"
           signals-handled)
   (exit (equal? signals-handled
                 `((second-handler . ,(getpid))
                   (first-handler . ,(getpid))
                   (first-handler . ,parent)))))

  (child
   (kill (getpid) SIGALRM)           ;first handler
   (sleep 1)                         ;give asyncs one more chance to run
   (format (current-error-port) "signals handled by the parent: ~s~%"
           signals-handled)
   (exit (and (equal? signals-handled
                      `((first-handler . ,parent)
                        (first-handler . ,parent)))
              (zero? (cdr (waitpid child)))))))

;;; Local Variables:
;;; mode: scheme
;;; End: