Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

oo-init-quota: allow tab delimiters in /etc/fstab #6353

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions node-util/sbin/oo-init-quota
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function get_fstab_mount_options() {
# get the current mount options for a given mount point
function get_current_mount_options() {
# options are the comma delimited string between parens
mount | egrep " $1 " | sed -e 's/^.*(// ; s/).*$// ' | sort -u
mount | egrep "\s+$1\s+" | sed -e 's/^.*(// ; s/).*$// ' | sort -u
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mount shouldn't output tabs, so this change shouldn't be necessary, but then again, it shouldn't hurt anything.

}

ORIGIN_MOUNTPOINT=$(get_mountpoint $origin_dir)
Expand All @@ -79,11 +79,11 @@ QUOTA_OPTIONS=usrjquota=aquota.user,jqfmt=vfsv0
function update_fstab() {
# ORIGIN_MOUNTPOINT=$1

if ! tr -s ' ' < /etc/fstab | egrep "^[^#].+ $1 ext4 [^ ]+$QUOTA_OPTIONS "; then
if ! tr -s '[:blank:]' < /etc/fstab | egrep "^[^#].+\s+$1\s+ext4\s+.*$QUOTA_OPTIONS\s+"; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting: [^ ]+ causes this old regex to fail to match if the quota options are not preceded by other options, so this change avoids adding duplicate $QUOTA_OPTIONS in that case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we change the last \s+ to [[:blank:],]+? Otherwise, this pattern fails to match if $QUOTA_OPTIONS is followed by further options.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .* before $QUOTA_OPTIONS will pick up any character, even spaces. This should probably be [^ ]* or even better [^\h] (which is shorthand for [^[:blank:]]). The [^ ]+ previously in this line is odd and probably incorrect. It requires a non-space character before the quota options when it is possible that the quota options may be first in the list of options.

FSTAB_OPTIONS=$(get_fstab_mount_options $1)
NEW_OPTIONS=${FSTAB_OPTIONS},${QUOTA_OPTIONS}
# NOTE: double quotes - Variables are shell-substituted before perl runs
perl -p -i -e "m: $1 : && s/${FSTAB_OPTIONS}/${NEW_OPTIONS}/" /etc/fstab
perl -p -i -e "m:\s+$1\s+: && s/${FSTAB_OPTIONS}/${NEW_OPTIONS}/" /etc/fstab
fi
}

Expand Down