]> granicus.if.org Git - zfs/commitdiff
zfs-functions.in: is_mounted() always returns 1
authorTerraTech <TerraTech@users.noreply.github.com>
Tue, 4 Dec 2018 17:57:29 +0000 (09:57 -0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 4 Dec 2018 17:57:29 +0000 (09:57 -0800)
The 'while read line; ...; done' loop is run in a piped subshell
therefore the 'return 0' would not cause a return from the
is_mounted() function.  In all cases, this function will
always return 1.

The fix is to 'return 1' from the subshell on a successful match
(no match == return 0), and then negating the final return value.

Reviewed-by: George Melikov <mail@gmelikov.ru>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: TerraTech <TerraTech@users.noreply.github.com>
Closes #8151

etc/init.d/zfs-functions.in

index f5b74d45824e5b764bdecfdd2cc9f9727ccc9dc3..490503e9139100e679d66a6705a999ecfd344b9b 100644 (file)
@@ -423,9 +423,14 @@ is_mounted()
        mount | \
            while read line; do
                if echo "$line" | grep -q " on $mntpt "; then
-                   return 0
+                   # returns:
+                   #   0 on unsuccessful match
+                   #   1 on a successful match
+                   return 1
                fi
            done
 
-       return 1
+       # The negation will flip the subshell return result where the default
+       # return value is 0 when a match is not found.
+       return $(( !$? ))
 }