[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] When pipes fail (and when not)
From: |
Paul Wagner |
Subject: |
Re: [Help-bash] When pipes fail (and when not) |
Date: |
Tue, 27 Nov 2018 14:32:48 +0100 |
User-agent: |
Posteo Webmail |
Dear Bob,
a really really huge Thank You for the effort you put into this
explanation!
Therefore I conclude that your Android environment is mistakenly
installing a SIG_IGN handler for SIGPIPE in the environment.
With that as a working hypothesis, could I install my own SIGPIPE
handler then and kill the subshell tee runs in? Something like
for i in {0..9}; do echo $i; sleep 1; done | { trap 'kill $$' pipe; tee
foo; } | dd bs=1 count=10
To experiment with that, I tried (under Cygwin, where the SIGPIPE is
working fine)
trap 'echo foo >&2' pipe
for i in {0..9}; do echo $i; sleep 1; done | dd bs=1 count=10
which terminates after '4' but never writes 'foo', making me wonder if
the trap handler ever got called. When I try
trap '' pipe
for i in {0..9}; do echo $i; sleep 1; done | dd bs=1 count=10
as you did in your expose, I get the expected behaviour of
0
1
2
3
4
10+0 records in
10+0 records out
10 bytes copied, 4.10439 s, 0.0 kB/s
-bash: echo: write error: Broken pipe
-bash: echo: write error: Broken pipe
-bash: echo: write error: Broken pipe
-bash: echo: write error: Broken pipe
-bash: echo: write error: Broken pipe
so setting the trap handler actually works in this case, but why not in
the former one? Or did I miss something else?
For what it is worth I tried this on Android using Termux and
received the same result. I feel confident that the parent
environment ignoring SIGPIPE is the problem.
Interesting is that inside Termux the behaviour is the same. I am not
familiar with Termux, but GNUroot uses a proot-environment, and from
what I read in the FAQ Termux might operate the same way. I will
probably have a look at the proot sources, might find a clue there.
P.S.: I noticed that with GNURoot on android, process substitution
does not
work, probably because /dev can not be written? Is that related to
the
problem above?
No. I don't think so. That would be a different problem. And
strictly speaking that isn't a portable operation anyway.
Regarding process substitution not working, in the meantime I found out
that /dev is just lacking the /dev/fd-directory, but /proc has it, so on
a rooted Android device a simple 'ln -s /proc/self/fd /dev/fd' before
starting the proot-environment does the trick.
Again, a big Thank You!
Paul
P.S.
P.S. Using {0..9} as in "for i in {0..9}" is really not a good way to
do this. It expands to be the full set.
for i in 0 1 2 3 4 5 6 7 8 9
For 10 items this is okay. But people get used to doing that and then
do it for 10 zillion items. That eats up a *LOT* of memory.
I get your point. I just wanted to make the example *really* short, and
I never intended more than 10 iterations.
And next I am of the opinion that counting numbers should be whole
counting numbers starting at 1 not 0 and proceeding on from there.
Totally agree. I'm just *very* lazy, and typing 0..9 saved me one
keystroke compared to 1..10 ;-)
- [Help-bash] When pipes fail (and when not), Paul-Jürgen Wagner, 2018/11/05
- Re: [Help-bash] When pipes fail (and when not), Bob Proulx, 2018/11/24
- Re: [Help-bash] When pipes fail (and when not),
Paul Wagner <=
- Re: [Help-bash] When pipes fail (and when not), Chet Ramey, 2018/11/27
- Re: [Help-bash] When pipes fail (and when not), Paul Wagner, 2018/11/28
- Re: [Help-bash] When pipes fail (and when not), Eric Blake, 2018/11/28
- Re: [Help-bash] When pipes fail (and when not), Paul Wagner, 2018/11/28
- Re: [Help-bash] When pipes fail (and when not), Eric Blake, 2018/11/28
- Re: [Help-bash] When pipes fail (and when not), Paul Wagner, 2018/11/28
- Re: [Help-bash] When pipes fail (and when not), Chet Ramey, 2018/11/28
- Re: [Help-bash] When pipes fail (and when not), Bob Proulx, 2018/11/28
- Re: [Help-bash] When pipes fail (and when not), Chet Ramey, 2018/11/28