1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Speed up 'read', fixing macOS hang

This fixes a hanging bug that could occur on macOS when using the
'read' command to read from a FIFO and encountering end-of-file
without a final newline character. It also makes the 'read' command
perform 15-25% faster on macOS and Linux and maybe other systems.

src/lib/libast/sfio/sfpkrd.c: sfpkrd():
- Get rid of the optional stuff that uses the poll(2) or select(2)
  syscalls. The only thing that is required to avoid regressions is
  the code that was conditional upon the socket_peek feature test,
  which tests for the correct functioning of the recv(2) syscall.
  This has now been made mandatory. The rest now uses what was
  previously a fallback in plain C, resulting in a function that is
  not only more readable, but actually faster than the syscalls.

Resolves: https://github.com/ksh93/ksh/issues/118
This commit is contained in:
Martijn Dekker 2020-08-19 01:36:01 +01:00
parent c3388ffd85
commit ff385e5a89
4 changed files with 40 additions and 232 deletions

View file

@ -583,5 +583,19 @@ then exec 3>&-
err_exit "Open file descriptor leaks out of subshell"
fi
# ======
# On unpatched ksh on macOS, 'read' used to block when reading from a FIFO and there was no final newline.
if mkfifo "$tmp/fifo_no_lf"
then trap 'sleep_pid=0; kill "$ksh_pid"; err_exit "'\''read'\'' hangs on EOF without final linefeed when reading from FIFO"' TERM
(sleep 1; kill "$$") &
sleep_pid=$!
"$SHELL" -c 'print -n foo >$0 & while read f; do :; done <$0' "$tmp/fifo_no_lf" &
ksh_pid=$!
wait "$ksh_pid"
trap - TERM
((sleep_pid)) && kill "$sleep_pid"
else err_exit "mkfifo failed; cannot test reading from FIFO"
fi
# ======
exit $((Errors<125?Errors:125))