Fixes #6482 Check sysctl file path and catch read exceptions

This commit is contained in:
James Tanner 2014-03-14 11:16:45 -04:00
parent 0c70cc123e
commit 59fb47ae9a

View file

@ -235,7 +235,16 @@ class SysctlModule(object):
# Get the token value from the sysctl file # Get the token value from the sysctl file
def read_sysctl_file(self): def read_sysctl_file(self):
lines = open(self.sysctl_file, "r").readlines()
lines = []
if os.path.isfile(self.sysctl_file):
try:
f = open(self.sysctl_file, "r")
lines = f.readlines()
f.close()
except IOError, e:
self.module.fail_json(msg="Failed to open %s: %s" % (self.sysctl_file, str(e)))
for line in lines: for line in lines:
line = line.strip() line = line.strip()
self.file_lines.append(line) self.file_lines.append(line)