| 1 |
#!/bin/sh |
| 2 |
exec guile -q -s "$0" "$@" |
| 3 |
!# |
| 4 |
|
| 5 |
;;; Exercise the 'e' flag to 'open-file' (O_CLOEXEC). |
| 6 |
|
| 7 |
(unless (provided? 'fork) |
| 8 |
(exit 77)) |
| 9 |
|
| 10 |
(define file |
| 11 |
(string-append (or (getenv "TMPDIR") "/tmp") |
| 12 |
"/guile-test-close-on-exec-" |
| 13 |
(number->string (getpid)) ".txt")) |
| 14 |
|
| 15 |
;;; Since fcntl(2) F_GETFD does not return flags such as O_CLOEXEC, |
| 16 |
;;; create a child process, call 'exec', and make sure it doesn't |
| 17 |
;;; inherit the file descriptor. |
| 18 |
(let ((port (open-file file "we"))) |
| 19 |
(display "Hello!\n" port) |
| 20 |
(let ((pid (primitive-fork))) |
| 21 |
(if (zero? pid) |
| 22 |
(dynamic-wind |
| 23 |
(const #t) |
| 24 |
(lambda () |
| 25 |
(execlp "guile" "guile" "-c" |
| 26 |
(object->string |
| 27 |
`(catch #t |
| 28 |
(lambda () |
| 29 |
(fdopen ,(fileno port) "w") |
| 30 |
(primitive-exit 0)) |
| 31 |
(lambda (key . args) |
| 32 |
(pk 'child-exception args) |
| 33 |
(if (and (eq? key 'system-error) |
| 34 |
(= EBADF (system-error-errno (cons key args)))) |
| 35 |
(primitive-exit 1) |
| 36 |
(primitive-exit 2))))))) |
| 37 |
(lambda () |
| 38 |
(primitive-exit 3))) |
| 39 |
(let ((status (pk 'child-status (cdr (waitpid pid))))) |
| 40 |
(false-if-exception (delete-file file)) |
| 41 |
(exit (equal? (status:exit-val status) 1)))))) |