Fixes _find_binaries not using globals

_find_binaries now sets the right globals
Binaries are now properly populated (reverse path/binary for loops)
pull/603/head
Michel Blanc 13 years ago
parent 572868c9e1
commit a7e4da92db

@ -41,6 +41,8 @@ def fail_json(d):
def _find_binaries(): def _find_binaries():
# list of possible paths for service/chkconfig binaries # list of possible paths for service/chkconfig binaries
# with the most probable first # with the most probable first
global CHKCONFIG
global SERVICE
paths = ['/sbin', '/usr/sbin', '/bin', '/usr/bin'] paths = ['/sbin', '/usr/sbin', '/bin', '/usr/bin']
binaries = [ 'service', 'chkconfig', 'update-rc.d' ] binaries = [ 'service', 'chkconfig', 'update-rc.d' ]
location = dict() location = dict()
@ -48,13 +50,11 @@ def _find_binaries():
for binary in binaries: for binary in binaries:
location[binary] = None location[binary] = None
for path in paths: for binary in binaries:
for binary in binaries: for path in paths:
if os.path.exists(path + '/' + binary): if os.path.exists(path + '/' + binary):
location[binary] = path + '/' + binary location[binary] = path + '/' + binary
break break
if location.get('chkconfig', None): if location.get('chkconfig', None):
CHKCONFIG = location['chkconfig'] CHKCONFIG = location['chkconfig']
@ -62,12 +62,12 @@ def _find_binaries():
CHKCONFIG = location['update-rc.d'] CHKCONFIG = location['update-rc.d']
else: else:
fail_json(dict(failed=True, msg='unable to find chkconfig or update-rc.d binary')) fail_json(dict(failed=True, msg='unable to find chkconfig or update-rc.d binary'))
if location.get('service', None): if location.get('service', None):
SERVICE = location['service'] SERVICE = location['service']
else: else:
fail_json(dict(failed=True, msg='unable to find service binary')) fail_json(dict(failed=True, msg='unable to find service binary'))
def _run(cmd): def _run(cmd):
# returns (rc, stdout, stderr) from shell command # returns (rc, stdout, stderr) from shell command
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
@ -186,11 +186,11 @@ if state or enable:
rc_state = rc and rc1 and rc2 rc_state = rc and rc1 and rc2
stdout = stdout1 + stdout2 stdout = stdout1 + stdout2
stderr = stderr1 + stderr2 stderr = stderr1 + stderr2
out += stdout out += stdout
err += stderr err += stderr
rc = rc and rc_state rc = rc and rc_state
if rc != 0: if rc != 0:
print json.dumps({ print json.dumps({
@ -224,7 +224,7 @@ elif list_items is not None:
else: else:
print json.dumps(dict(failed=True, msg="expected state or list parameters")) print json.dumps(dict(failed=True, msg="expected state or list parameters"))
sys.exit(0) sys.exit(0)

Loading…
Cancel
Save