Prevent redundant commenting by drive-audit

The drive-audit detects error log about a device and comments out it
in /etc/fstab. When the error log is generated several times, it
comments out the line for each time.
This patch makes drive-audit to check if the device is already
commented out, and prevents redundant commenting out.

Change-Id: Ia542d35b58552dde0f324bb9c42531f98c9058fa
This commit is contained in:
Takashi Kajinami 2015-01-23 20:16:20 +09:00
parent 7def1d2921
commit a270dca239

View File

@ -126,7 +126,9 @@ def comment_fstab(mount_point):
with open('/etc/fstab.new', 'w') as new_fstab:
for line in fstab:
parts = line.split()
if len(parts) > 2 and line.split()[1] == mount_point:
if len(parts) > 2 \
and parts[1] == mount_point \
and not line.startswith('#'):
new_fstab.write('#' + line)
else:
new_fstab.write(line)