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

Re: Regression with stdin handling in non-interactive mode between 5.8 and 5.8.1



Woo - seems to fix the problem on my end! :)

Don't know if y'all use these, but feel free to consider this patch:

Tested-by: Lyude Paul <lyude@xxxxxxxxxx>

On Thu, 2022-03-03 at 11:52 +0000, Peter Stephenson wrote:
> diff --git a/Src/input.c b/Src/input.c
> index caeaff0e3..50cd2cd78 100644
> --- a/Src/input.c
> +++ b/Src/input.c
> @@ -223,13 +223,20 @@ shingetchar(void)
>         return STOUC(*shinbufptr++);
>  
>      shinbufreset();
> -    do {
> +    for (;;) {
>         errno = 0;
> -       nread = read(SHIN, shinbuffer, SHINBUFSIZE);
> -    } while (nread < 0 && errno == EINTR);
> -    if (nread <= 0)
> +       nread = read(SHIN, shinbufendptr, 1);
> +       if (nread > 0) {
> +           /* Use line buffering (POSIX requirement) */
> +           if (*shinbufendptr++ == '\n')
> +               break;
> +           if (shinbufendptr == shinbuffer + SHINBUFSIZE)
> +               break;
> +       } else if (nread == 0 || errno != EINTR)
> +           break;
> +    }
> +    if (shinbufendptr == shinbuffer)
>         return -1;
> -    shinbufendptr = shinbuffer + nread;
>      return STOUC(*shinbufptr++);
>  }
>  
> diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst
> index 4e39a8f3c..0312fe94e 100644
> --- a/Test/A01grammar.ztst
> +++ b/Test/A01grammar.ztst
> @@ -961,3 +961,12 @@ F:Note that the behaviour of 'exit' inside try-list
> inside a function is unspeci
>  F:This test was written to ensure the behaviour doesn't change silently.
>  F:If this test fails during development, it *might* be appropriate to
> change
>  F:its expectations.
> +
> + (
> +   export VALUE=first
> +   print -l 'echo Value is $VALUE' 'VALUE=second sh' 'echo Value is $VALUE'
> |
> +   $ZTST_testdir/../Src/zsh -f
> + )
> +0:Non-interactive shell command input is line buffered
> +>Value is first
> +>Value is second

-- 
Cheers,
 Lyude Paul (she/her)
 Software Engineer at Red Hat





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