Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: ZSH performance regression in 5.8.1.2-test



> 2022/04/26 16:01, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> 
> Try this?
> <sysread.txt>
--- a/Src/input.c
+++ b/Src/input.c
(snip)
+#ifdef HAVE_FSTAT
+    else {
+      struct stat st;
+      if (fstat(SHIN, &st) == 0 && !S_ISFIFO(st.st_mode))
+         rsize = SHINBUFSIZE;
+    }
+#endif

It works for
printf '%s\n' 'echo $$' sh 'echo $$' | zsh

But in theory (yes, just in theory), SHIN can be a socket.
With two terminals A and B (zsh/socket already zmodload'ed):

A% zsocket -l /tmp/tmpsocket
A% zsocket -a $REPLY

B% zsocket /tmp/tmpsocket

A% zsh <&$REPLY

B% printf '%s\n' 'echo $$' sh 'echo $$' >&$REPLY

then on the terminal A:
zsh: lseek(0, -11): illegal seek


Adding !S_ISSOCK(st.st_mode) solves this, of course.
But at least on my Mac the following seems to work also:

    if (lseek(SHIN, 0, SEEK_CUR) == 0)
          rsize = SHINBUFSIZE;

# Have you found a case in which lseek(SHIN, 0, SEEK_CUR) fails
# when it shouldn't fail, or does not fail when it should fail?
If you think using fstat() is safer then I have no objection.

PS
Either fstat()/S_ISFIFO() or lseek() works when SHIN is a FIFO:
A% mkfifo fifo
A% zsh < fifo
B% printf '%s\n' 'echo $$' sh 'echo $$' > fifo




Messages sorted by: Reverse Date, Date, Thread, Author