From 59fb47ae9a25a621f075d7a5657519cf2c46b08d 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 --- system/sysctl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/system/sysctl b/system/sysctl index 97e5bc5e6c1..1b29fed8f1e 100644 --- a/system/sysctl +++ b/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)