Skip to contentSkip to conversation

regression in reading variables from pipe for external processes (Issue #8)

herbertx/dash New Herbert Xu 1 participant 2 messages Jul 24, 2024 2 messages not in the archive

lore
Share & tools
lore

Herbert Xu

author
#1 lore raw
In reply to a message not in the archive
Quoted 21 lines · arĉi

this script

```shell
printf '1\n2\n' | while read i; do
	/bin/echo "$i"
done
```
outputs
```
1
```
while this script
```shell
printf '1\n2\n' | while read i; do
	echo "$i"
done
```
outputs
```
1
2
```
Quoted 3 lines

(as expected)
both scripts emit second output on release.
git-bisect revealed this was introduced in 44b15ea09a9ee5872cf477e4ffc6b42ef37d1e46

Thanks for the report.

This means that fallback code-path when tee(2) isn't available isn't working. Perhaps the seek testing isn't working as expected.

Unfortunately I couldn't reproduce this on Linux. Please tell us what OS you're using and provide a strace of the failing execution.

There was another similar report about this:

https://lore.kernel.org/dash/[email protected]/T/#t

Cheers,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
author
#3 lore raw

PATCH 1/1 eval: Reset input for pipelines

In reply to a message not in the archive
Quoted 3 lines · arĉi

I'm on Arch Linux.
<details><summary>strace</summary>

Oops, this has nothing to do with the other bug report. Indeed I could reproduce this. The issue is a missing reset_input call for pipelines.

Thanks,

---8<---
For everything but the first component of a pipeline, the input needs to be reset because it is no longer equal to that of the parent shell.

Fixes b1864ee9f241 ("input: Use lseek on stdin when possible")
---
 src/eval.c | 1 +
 1 file changed, 1 insertion(+)
src/eval.c +1 -0
index ad2aa03..0f2a7ba 100644
@@ -595,6 +595,7 @@ evalpipe(union node *n, int flags)
 				close(pip[0]);
 			}
 			if (prevfd > 0) {
+				reset_input();
 				dup2(prevfd, 0);
 				close(prevfd);
 			}
Signature · 6 lines
2.39.2

-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt