OILS / demo / eintr.sh View on Github | oilshell.org

47 lines, 12 significant
1#!/usr/bin/env bash
2#
3# Test out our modifications to posixmodule.c to handle EINTR.
4#
5# Usage:
6# ./eintr.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11
12posix-test() {
13 PYTHONPATH=.:vendor EINTR_TEST=1 \
14 pyext/posix_test.py "$@"
15}
16
17test-read() { posix-test PosixTest.testRead; }
18test-wait() { posix-test PosixTest.testWait; }
19test-waitpid() { posix-test PosixTest.testWaitpid; }
20test-write() { posix-test PosixTest.testWrite; }
21
22# Conclusion: print CAN raise IOError with EINTR.
23#
24# It might be better to make our own functions:
25#
26# io.echo() # print()
27# io.log() # print() to stderr
28
29# NOTE: print() is a complicated function that ends up looking up
30# sys.stdout.write(). So fixing write should fix print!
31# But for simplicity, we could still get rid of print(). It's a complicated
32# function with too many args.
33
34test-print() { posix-test PosixTest.testPrint; }
35
36# NOTES:
37#
38# - PEP 475 says that Python purposesly ignores EINTR on close() and dup2().
39# The reason is due to multi-threaded programs: close() and dup2() change
40# the descriptor table, so another thread could have reused the file
41# descriptor in that time! This doesn't apply to the shell, so maybe we
42# should handle them?
43
44# - The parts of fcntl() we use don't appear to return EINTR. Not covered by
45# PEP 475.
46
47"$@"