Skip to content

Commit

Permalink
Fix zfs-mount-generator for datasets with spaces
Browse files Browse the repository at this point in the history
Alternative implementation of @rlaager's original modification
of zfs-mount-generator fix, with @chrisrd's comments. Set
IFS to be only the tab character, matching our `-H` call in
`zfs list`, allowing spaces to appear in dataset names (and
mountpoints).

Also adds comments explaining our rationale.

Reviewed-by: Chris Dunlop <chris@onthe.net.au>
Reviewed-by: Richard Laager <rlaager@wiktel.com>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Signed-off-by: Antonio Russo <antonio.e.russo@gmail.com>
Closes #8708 
Closes #8718
  • Loading branch information
aerusso authored and behlendorf committed May 7, 2019
1 parent bca0641 commit 6aff30a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions etc/systemd/system-generators/zfs-mount-generator.in
Expand Up @@ -22,7 +22,7 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

set -ef
set -e

FSLIST="@sysconfdir@/zfs/zfs-list.cache"

Expand Down Expand Up @@ -55,7 +55,12 @@ mkdir -p "${req_dir}"

process_line() {

# -o name
# zfs list -H -o name,...
# fields are tab separated
IFS="$(printf '\t')"
# protect against special characters in, e.g., mountpoints
set -f
set -- $1
dataset="${1}"
p_mountpoint="${2}"
p_canmount="${3}"
Expand Down Expand Up @@ -175,7 +180,7 @@ process_line() {
# Automatically generated by zfs-mount-generator
[Unit]
SourcePath=${FSLIST}/${cachefile}
SourcePath=${cachefile}
Documentation=man:zfs-mount-generator(8)
Before=local-fs.target zfs-mount.service
After=zfs-import.target
Expand All @@ -193,8 +198,8 @@ EOF
}

# Feed each line into process_line
for cachefile in $(ls "${FSLIST}") ; do
for cachefile in "${FSLIST}/"* ; do
while read -r fs ; do
process_line $fs
done < "${FSLIST}/${cachefile}"
process_line "${fs}"
done < "${cachefile}"
done

0 comments on commit 6aff30a

Please sign in to comment.