From 9d6518de5a9e76aed8b7ec3b79c4ae693c1caa6c Mon Sep 17 00:00:00 2001 From: James Tanner Date: Fri, 14 Mar 2014 11:16:45 -0400 Subject: [PATCH] Fixes #6482 Check sysctl file path and catch read exceptions --- library/system/sysctl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/library/system/sysctl b/library/system/sysctl index 97e5bc5e6c1..1b29fed8f1e 100644 --- a/library/system/sysctl +++ b/library/system/sysctl @@ -235,7 +235,16 @@ class SysctlModule(object): # Get the token value from the sysctl file 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: line = line.strip() self.file_lines.append(line)