Python 3 fixes for async_wrapper and async_status. (#4671)

reviewable/pr18780/r1
Matt Clay 8 years ago committed by GitHub
parent 05c6707a32
commit 982c4557d2

@ -79,7 +79,7 @@ def main():
data = None data = None
try: try:
data = file(log_path).read() data = open(log_path).read()
data = json.loads(data) data = json.loads(data)
except Exception: except Exception:
if not data: if not data:

@ -32,6 +32,8 @@ import signal
import time import time
import syslog import syslog
PY3 = sys.version_info[0] == 3
syslog.openlog('ansible-%s' % os.path.basename(__file__)) syslog.openlog('ansible-%s' % os.path.basename(__file__))
syslog.syslog(syslog.LOG_NOTICE, 'Invoked with %s' % " ".join(sys.argv[1:])) syslog.syslog(syslog.LOG_NOTICE, 'Invoked with %s' % " ".join(sys.argv[1:]))
@ -64,7 +66,7 @@ def daemonize_self():
e = sys.exc_info()[1] e = sys.exc_info()[1]
sys.exit("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror)) sys.exit("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror))
dev_null = file('/dev/null','rw') dev_null = open('/dev/null', 'w')
os.dup2(dev_null.fileno(), sys.stdin.fileno()) os.dup2(dev_null.fileno(), sys.stdin.fileno())
os.dup2(dev_null.fileno(), sys.stdout.fileno()) os.dup2(dev_null.fileno(), sys.stdout.fileno())
os.dup2(dev_null.fileno(), sys.stderr.fileno()) os.dup2(dev_null.fileno(), sys.stderr.fileno())
@ -85,6 +87,9 @@ def _run_module(wrapped_cmd, jid, job_path):
cmd = shlex.split(wrapped_cmd) cmd = shlex.split(wrapped_cmd)
script = subprocess.Popen(cmd, shell=False, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE) script = subprocess.Popen(cmd, shell=False, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(outdata, stderr) = script.communicate() (outdata, stderr) = script.communicate()
if PY3:
outdata = outdata.decode('utf-8', 'surrogateescape')
stderr = stderr.decode('utf-8', 'surrogateescape')
result = json.loads(outdata) result = json.loads(outdata)
if stderr: if stderr:
result['stderr'] = stderr result['stderr'] = stderr

Loading…
Cancel
Save