Skip to content

Commit

Permalink
lenses/fstab.aug: Allow individual mount options to be empty
Browse files Browse the repository at this point in the history
Mount allows mount-option fields to be empty (I think it ignores
them), but augeas gave an error.  Allow this to be parsed, preserving
the empty option on write.

Example:
  /dev/mapper/vg00-vartmp /var/tmp xfs rw,,nodev,nosuid,noexec,relatime 0 0

Note this generalises earlier commit 5246ef0 ("lenses/fstab.aug:
Allow comma after the last option (hercules-team#838)") since "," appearing at the
end of the option list is a special case of this.

Fixes: https://issues.redhat.com/browse/RHEL-77279
Fixes: hercules-team#832
Signed-off-by: Richard W.M. Jones <[email protected]>
  • Loading branch information
rwmjones committed Feb 4, 2025
1 parent 4ac2526 commit d6cd9b0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lenses/fstab.aug
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ module Fstab =
Build.opt_list lns comma

(* A mount option label can't contain comma, comment, equals, or space *)
let optlabel = /[^,#= \n\t]+/
let mntoptlabel = /[^,#= \n\t]+/

let comma_sep_list (l:string) =
let mntopt_list (l:string) =
let value = [ label "value" . Util.del_str "=" . ( store Rx.neg1 )? ] in
let lns = [ label l . store optlabel . value? ] in
let mntopt = [ label l . store mntoptlabel . value? ] in
let lns = mntopt? in
Build.opt_list lns comma

let record = [ seq "mntent" .
Util.indent .
[ label "spec" . store spec ] . sep_tab .
[ label "file" . store file ] . sep_tab .
vfstype_list "vfstype" .
(sep_tab . comma_sep_list "opt" .
(sep_tab . mntopt_list "opt" .
(sep_tab . [ label "dump" . store /[0-9]+/ ] .
( sep_spc . [ label "passno" . store /[0-9]+/ ])? )? )?
. Util.comment_or_eol ]
Expand Down
24 changes: 24 additions & 0 deletions lenses/tests/test_fstab.aug
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,30 @@ module Test_fstab =
{ "#comment" = "device at install: /dev/sda3" }
}

(* Bug #832 - Allow comma after the last option *)
test Fstab.lns get "/dev/mapper/foo-bar / xfs defaults, 0 0\n" =
{ "1"
{ "spec" = "/dev/mapper/foo-bar" }
{ "file" = "/" }
{ "vfstype" = "xfs" }
{ "opt" = "defaults" }
{ "dump" = "0" }
{ "passno" = "0" }
}

(* RHEL-77279 - Allow empty option *)
test Fstab.lns get "/dev/mapper/foo-bar / xfs rw,,nodev 0 0\n" =
{ "1"
{ "spec" = "/dev/mapper/foo-bar" }
{ "file" = "/" }
{ "vfstype" = "xfs" }
{ "opt" = "rw" }
{ "opt" = "" }
{ "opt" = "nodev" }
{ "dump" = "0" }
{ "passno" = "0" }
}

(* Local Variables: *)
(* mode: caml *)
(* End: *)

0 comments on commit d6cd9b0

Please sign in to comment.