Tweak error checking for "enabled" code.

Based on input from @jarmani:
* A return value of 2 now means a service does not exist. Instead of
  trying to handle the different meanings of rc after running "status",
  just look at stderr to know if something failed.
* Skip looking at stdout to make the code cleaner. Any errors should
  turn up on stderr.
pull/18777/head
Patrik Lundin 10 years ago committed by Matt Clay
parent 32cb025b85
commit 25c3c03a11

@ -1022,6 +1022,9 @@ class OpenBsdService(Service):
rc, stdout, stderr = self.execute_command("%s %s %s" % (self.enable_cmd, 'status', self.name)) rc, stdout, stderr = self.execute_command("%s %s %s" % (self.enable_cmd, 'status', self.name))
if stderr:
self.module.fail_json(msg=stderr)
if self.enable: if self.enable:
action = "enable %s flags %s" % (self.name, self.arguments) action = "enable %s flags %s" % (self.name, self.arguments)
args = self.arguments args = self.arguments
@ -1030,8 +1033,6 @@ class OpenBsdService(Service):
else: else:
action = "disable %s" % self.name action = "disable %s" % self.name
if rc == 1: if rc == 1:
if stderr:
self.module.fail_json(msg=stderr)
return return
if self.module.check_mode: if self.module.check_mode:
@ -1042,8 +1043,6 @@ class OpenBsdService(Service):
if rc != 0: if rc != 0:
if stderr: if stderr:
self.module.fail_json(msg=stderr) self.module.fail_json(msg=stderr)
elif stdout:
self.module.fail_json(msg=stdout)
else: else:
self.module.fail_json(msg="rcctl failed to modify service enablement") self.module.fail_json(msg="rcctl failed to modify service enablement")

Loading…
Cancel
Save