diff mbox series

[v2] common/rc: fix MKSWAP_PROG quoting

Message ID 20210901054822.phzkg5xqoocx3duq@xzhoux.usersys.redhat.com (mailing list archive)
State New, archived
Headers show
Series [v2] common/rc: fix MKSWAP_PROG quoting | expand

Commit Message

Murphy Zhou Sept. 1, 2021, 6:16 a.m. UTC
After commit
  0e4dd8b9 common/rc: fix ignoring of errors on
we are getting this error message when running swapfiles tests:
  +./common/rc: line 2553: MKSWAP_PROG: command not found

Rewrite the line and add a filter for mkswap.

Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---

Thanks all for the suggestions!

v2:
  rewrite the line and add a filter
  source filters for generic/643

 common/filter     | 6 ++++++
 common/rc         | 2 +-
 tests/generic/643 | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

Comments

Dave Chinner Sept. 1, 2021, 7:15 a.m. UTC | #1
On Wed, Sep 01, 2021 at 02:16:20PM +0800, Murphy Zhou wrote:
> After commit
>   0e4dd8b9 common/rc: fix ignoring of errors on
> we are getting this error message when running swapfiles tests:
>   +./common/rc: line 2553: MKSWAP_PROG: command not found
> 
> Rewrite the line and add a filter for mkswap.
> 
> Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> ---
> 
> Thanks all for the suggestions!
> 
> v2:
>   rewrite the line and add a filter
>   source filters for generic/643
> 
>  common/filter     | 6 ++++++
>  common/rc         | 2 +-
>  tests/generic/643 | 1 +
>  3 files changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/common/filter b/common/filter
> index 2efbbd99..0883a3fd 100644
> --- a/common/filter
> +++ b/common/filter
> @@ -661,5 +661,11 @@ _filter_quota_report()
>  		s|^(.*?) (\d+) (\d+) (\d+)|$1 @{[$2 * 1024 /'$bsize']} @{[$3 * 1024 /'$bsize']} @{[$4 * 1024 /'$bsize']}|'
>  }
>  
> +# Filter mkswap warning about the permissions
> +_filter_mkswap_stderr()
> +{
> +	grep -v "insecure permission"
> +}
> +

This is a one-off, specific filter and the "stderr" part of the name
makes no sense. If you want this to be a generic filter, the name
is "_filter_insecure_permission()", not it's calling context.

But that just shows that this does not need to be in the common
filter code - doing so just makes readers have to go look up what
the filter is. That is:

>  # make sure this script returns success
>  /bin/true
> diff --git a/common/rc b/common/rc
> index 46b6b220..0a3933a5 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -2550,7 +2550,7 @@ _format_swapfile() {
>  	$CHATTR_PROG +C "$fname" > /dev/null 2>&1
>  	_pwrite_byte 0x61 0 "$sz" "$fname" >> $seqres.full
>  	# Ignore permission complaints on filesystems that don't support perms
> -	$(MKSWAP_PROG "$fname" 2> >(grep -v 'insecure permission' >&2)) >> $seqres.full
> +	$MKSWAP_PROG "$fname" 2>&1 >> $seqres.full | _filter_mkswap_stderr

	$MKSWAP_PROG "$fname" 2>&1 >> $seqres.full | \
		grep -v "insecure permission"

will do what you want and is much more readable and easier to
understand.

Cheers,

Dave.
diff mbox series

Patch

diff --git a/common/filter b/common/filter
index 2efbbd99..0883a3fd 100644
--- a/common/filter
+++ b/common/filter
@@ -661,5 +661,11 @@  _filter_quota_report()
 		s|^(.*?) (\d+) (\d+) (\d+)|$1 @{[$2 * 1024 /'$bsize']} @{[$3 * 1024 /'$bsize']} @{[$4 * 1024 /'$bsize']}|'
 }
 
+# Filter mkswap warning about the permissions
+_filter_mkswap_stderr()
+{
+	grep -v "insecure permission"
+}
+
 # make sure this script returns success
 /bin/true
diff --git a/common/rc b/common/rc
index 46b6b220..0a3933a5 100644
--- a/common/rc
+++ b/common/rc
@@ -2550,7 +2550,7 @@  _format_swapfile() {
 	$CHATTR_PROG +C "$fname" > /dev/null 2>&1
 	_pwrite_byte 0x61 0 "$sz" "$fname" >> $seqres.full
 	# Ignore permission complaints on filesystems that don't support perms
-	$(MKSWAP_PROG "$fname" 2> >(grep -v 'insecure permission' >&2)) >> $seqres.full
+	$MKSWAP_PROG "$fname" 2>&1 >> $seqres.full | _filter_mkswap_stderr
 }
 
 _swapon_file() {
diff --git a/tests/generic/643 b/tests/generic/643
index 2bb9d220..9b067ea2 100755
--- a/tests/generic/643
+++ b/tests/generic/643
@@ -21,6 +21,7 @@  _cleanup()
 	rm -f $tmp.*
 	test -n "$swapfile" && swapoff $swapfile &> /dev/null
 }
+. ./common/filter
 
 # real QA test starts here
 _supported_fs generic