From aea822c47a6955d7836248ba80c554677e639cb8 Mon Sep 17 00:00:00 2001 From: Michel Blanc Date: Wed, 20 Feb 2013 12:42:49 +0100 Subject: [PATCH] Removes exception is sysctl file is missing When syscl file was missing, sysctl module was complaining about it and bailing out. This behaviour prevents usage of /etc/sysctl.d directory, present in some distributions. This patch accepts a missing sysctl.conf file so sysctl.d directory can be used. However, it will bail out if the destination directory doesn't exist. --- sysctl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sysctl b/sysctl index 9b2cbebfa51..48c28be8ffb 100644 --- a/sysctl +++ b/sysctl @@ -158,12 +158,14 @@ def sysctl_check(current_step, **sysctl_args): # sysctl file exists and openable ? # TODO choose if prefered to use os.access() instead try/catch on open if current_step == 'before': - try: - f = open(sysctl_args['sysctl_file']) - f.close() - except IOError, e: - return 1, 'unable to open supplied sysctl.conf' - + if not os.access(sysctl_args['sysctl_file'], os.W_OK): + try: + f = open(sysctl_args['sysctl_file'],'w') + f.write('') + f.close() + except IOError, e: + return 1, 'unable to create supplied sysctl file (directory missing)' + # no smart checks at this step ? if sysctl_args['checks'] == 'none': return 0, ''