diff mbox series

[v2,03/10] base-files: upgrade: add get_image_dd()

Message ID 20201110022223.41175-4-yszhou4tech@gmail.com
State Superseded, archived
Delegated to: Yousong Zhou
Headers show
Series sysupgrade: reword and organize log lines | expand

Commit Message

Yousong Zhou Nov. 10, 2020, 2:22 a.m. UTC
This is mainly to handle stderr message "Broken pipe", "F+P records
in/out" by common pattern "xcat | dd .."

Ref: https://bugs.openwrt.org/index.php?do=details&task_id=3140
Reported-by: Philip Prindeville <philipp@redfish-solutions.com>
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
---
 package/base-files/files/lib/upgrade/common.sh | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Philip Prindeville Nov. 10, 2020, 5:35 a.m. UTC | #1
Comments…


> On Nov 9, 2020, at 7:22 PM, Yousong Zhou <yszhou4tech@gmail.com> wrote:
> 
> This is mainly to handle stderr message "Broken pipe", "F+P records
> in/out" by common pattern "xcat | dd .."
> 
> Ref: https://bugs.openwrt.org/index.php?do=details&task_id=3140
> Reported-by: Philip Prindeville <philipp@redfish-solutions.com>
> Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
> ---
> package/base-files/files/lib/upgrade/common.sh | 6 ++++++
> 1 file changed, 6 insertions(+)
> 
> diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh
> index e12dfc9678..6c09908ee3 100644
> --- a/package/base-files/files/lib/upgrade/common.sh
> +++ b/package/base-files/files/lib/upgrade/common.sh
> @@ -94,6 +94,12 @@ get_image() { # <source> [ <command> ]
> 	$cmd <"$from"
> }
> 
> +get_image_dd() {
> +	local from="$1"; shift
> +
> +	( get_image "$from" | dd "$@" ) 2>&1 | grep -v -E ': Broken pipe| records (in|out)'


Can you through stdout onto another descriptor first, like 3, then move 2 to 1, run the grep, and then after the grep put 3 back onto 1?

I don’t like the idea of co-mingling stdout and stderr…

Thanks



> +}
> +
> get_magic_word() {
> 	(get_image "$@" | dd bs=2 count=1 | hexdump -v -n 2 -e '1/1 "%02x"') 2>/dev/null
> }
Yousong Zhou Nov. 10, 2020, 6:56 a.m. UTC | #2
On Tue, 10 Nov 2020 at 13:35, Philip Prindeville
<philipp@redfish-solutions.com> wrote:
>
> Comments…
>
>
> > On Nov 9, 2020, at 7:22 PM, Yousong Zhou <yszhou4tech@gmail.com> wrote:
> >
> > This is mainly to handle stderr message "Broken pipe", "F+P records
> > in/out" by common pattern "xcat | dd .."
> >
> > Ref: https://bugs.openwrt.org/index.php?do=details&task_id=3140
> > Reported-by: Philip Prindeville <philipp@redfish-solutions.com>
> > Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
> > ---
> > package/base-files/files/lib/upgrade/common.sh | 6 ++++++
> > 1 file changed, 6 insertions(+)
> >
> > diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh
> > index e12dfc9678..6c09908ee3 100644
> > --- a/package/base-files/files/lib/upgrade/common.sh
> > +++ b/package/base-files/files/lib/upgrade/common.sh
> > @@ -94,6 +94,12 @@ get_image() { # <source> [ <command> ]
> >       $cmd <"$from"
> > }
> >
> > +get_image_dd() {
> > +     local from="$1"; shift
> > +
> > +     ( get_image "$from" | dd "$@" ) 2>&1 | grep -v -E ': Broken pipe| records (in|out)'
>
>
> Can you through stdout onto another descriptor first, like 3, then move 2 to 1, run the grep, and then after the grep put 3 back onto 1?

Well, I tried a bit and I think it works ;)

root@OpenWrt:/tmp# cat a.sh
echo hello before
(exec 3>&2; sh /tmp/b.sh 2>&1 1>&3 | grep -v stderr; ) 2>&1
echo hello after
root@OpenWrt:/tmp# cat b.sh
echo hello stderr >&2
echo hello stdout >&1
root@OpenWrt:/tmp# sh a.sh
hello before
hello stdout
hello after
root@OpenWrt:/tmp# sh a.sh >/dev/null
root@OpenWrt:/tmp# sh a.sh 2>/dev/null
hello before
hello stdout
hello after
root@OpenWrt:/tmp#

>
> I don’t like the idea of co-mingling stdout and stderr…

I also had this concern and made sure all current users of
get_image_dd had "of=x" present.  That said, it's better if the
constraint is not there at all.

I will wait a while for more comments and send v3 with the redirection
trick if all goes well.

Regards,
               yousong
diff mbox series

Patch

diff --git a/package/base-files/files/lib/upgrade/common.sh b/package/base-files/files/lib/upgrade/common.sh
index e12dfc9678..6c09908ee3 100644
--- a/package/base-files/files/lib/upgrade/common.sh
+++ b/package/base-files/files/lib/upgrade/common.sh
@@ -94,6 +94,12 @@  get_image() { # <source> [ <command> ]
 	$cmd <"$from"
 }
 
+get_image_dd() {
+	local from="$1"; shift
+
+	( get_image "$from" | dd "$@" ) 2>&1 | grep -v -E ': Broken pipe| records (in|out)'
+}
+
 get_magic_word() {
 	(get_image "$@" | dd bs=2 count=1 | hexdump -v -n 2 -e '1/1 "%02x"') 2>/dev/null
 }