diff mbox series

common/rc: fix device size parser

Message ID 20191211201830.18911-1-dennis@kernel.org (mailing list archive)
State New, archived
Headers show
Series common/rc: fix device size parser | expand

Commit Message

Dennis Zhou Dec. 11, 2019, 8:18 p.m. UTC
If you have multiple devices that share the same regex (eg dm-1, dm10),
then _get_device_size() can return "$size\n$size" which causes the
following error for btrfs/011.

    QA output created by 011
    ./common/rc: line 3084: [: too many arguments

So, fix this by making grep check against eol.

Signed-off-by: Dennis Zhou <dennis@kernel.org>
---
 common/rc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Eryu Guan Dec. 15, 2019, 4:40 p.m. UTC | #1
On Wed, Dec 11, 2019 at 12:18:30PM -0800, Dennis Zhou wrote:
> If you have multiple devices that share the same regex (eg dm-1, dm10),
> then _get_device_size() can return "$size\n$size" which causes the
> following error for btrfs/011.
> 
>     QA output created by 011
>     ./common/rc: line 3084: [: too many arguments
> 
> So, fix this by making grep check against eol.
> 
> Signed-off-by: Dennis Zhou <dennis@kernel.org>
> ---
>  common/rc | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/common/rc b/common/rc
> index 5cdd829b..b819ede1 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -3583,7 +3583,7 @@ _get_available_space()
>  # return device size in kb
>  _get_device_size()
>  {
> -	grep `_short_dev $1` /proc/partitions | awk '{print $3}'
> +	grep "$(_short_dev $1)\$" /proc/partitions | awk '{print $3}'

I changed it to use "grep -w", which seems simpler.

Thanks,
Eryu

>  }
>  
>  # Make sure we actually have dmesg checking set up.
> -- 
> 2.17.1
>
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index 5cdd829b..b819ede1 100644
--- a/common/rc
+++ b/common/rc
@@ -3583,7 +3583,7 @@  _get_available_space()
 # return device size in kb
 _get_device_size()
 {
-	grep `_short_dev $1` /proc/partitions | awk '{print $3}'
+	grep "$(_short_dev $1)\$" /proc/partitions | awk '{print $3}'
 }
 
 # Make sure we actually have dmesg checking set up.