diff options
author | Simo Sorce <ssorce@redhat.com> | 2010-10-20 17:03:10 -0400 |
---|---|---|
committer | Simo Sorce <ssorce@redhat.com> | 2010-10-22 17:22:34 -0400 |
commit | f6a50c49ad39afabdce772b8cae2ae76ed9ea3d1 (patch) | |
tree | 23c6e6e926497b46d749832f1e6ea3b9642377b6 /ipaserver/install/ntpinstance.py | |
parent | 42c78a383d156e2ad7e6ae7832ccb1adc14d23c0 (diff) | |
download | freeipa.git-f6a50c49ad39afabdce772b8cae2ae76ed9ea3d1.tar.gz freeipa.git-f6a50c49ad39afabdce772b8cae2ae76ed9ea3d1.tar.xz freeipa.git-f6a50c49ad39afabdce772b8cae2ae76ed9ea3d1.zip |
Handle cases where ntpd options are scattered on multiple lines
Diffstat (limited to 'ipaserver/install/ntpinstance.py')
-rw-r--r-- | ipaserver/install/ntpinstance.py | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/ipaserver/install/ntpinstance.py b/ipaserver/install/ntpinstance.py index 3f7f7153..1c953167 100644 --- a/ipaserver/install/ntpinstance.py +++ b/ipaserver/install/ntpinstance.py @@ -1,6 +1,7 @@ # Authors: Karl MacMillan <kmacmillan@redhat.com> +# Authors: Simo Sorce <ssorce@redhat.com> # -# Copyright (C) 2007 Red Hat +# Copyright (C) 2007-2010 Red Hat # see file 'COPYING' for use and warranty information # # This program is free software; you can redistribute it and/or @@ -97,37 +98,40 @@ class NTPInstance(service.Service): fd.close() #read in memory, find OPTIONS, check/change it, then overwrite file - file_changed = False - found_options = False - ntpdsysc = [] + needopts = [ {'val':'-x', 'need':True}, + {'val':'-g', 'need':True} ] fd = open("/etc/sysconfig/ntpd", "r") - for line in fd: - sline = line.strip() - if sline.find("OPTIONS") == 0: - found_options = True - opts = sline.split("=", 1) - if len(opts) != 2: - optvals="" - else: - optvals = opts[1].strip(' "') - if optvals.find("-x") == -1: - optvals += " -x" - file_changed = True - if optvals.find("-g") == -1: - optvals += " -g" - file_changed = True - if file_changed: - line = 'OPTIONS="'+optvals+'"\n' - ntpdsysc.append(line) + lines = fd.readlines() fd.close() - if not found_options: - ntpdsysc.insert(0, 'OPTIONS="-x -g"\n') - file_changed = True - - if file_changed: + for line in lines: + sline = line.strip() + if not sline.startswith('OPTIONS'): + continue + sline = sline.replace('"', '') + for opt in needopts: + if sline.find(opt['val']) != -1: + opt['need'] = False + + newopts = [] + for opt in needopts: + if opt['need']: + newopts.append(opt['val']) + + done = False + if newopts: fd = open("/etc/sysconfig/ntpd", "w") - for line in ntpdsysc: - fd.write(line) + for line in lines: + if not done: + sline = line.strip() + if not sline.startswith('OPTIONS'): + fd.write(line) + continue + sline = sline.replace('"', '') + (variable, opts) = sline.split('=', 1) + fd.write('OPTIONS="%s %s"\n' % (opts, ' '.join(newopts))) + done = True + else: + fd.write(line) fd.close() def __stop(self): |