Fix stealth exceptions and blocking select() in daemonize() (#81064)

* Fix stealth exceptions and blocking select() in daemonize()

* Add changelog entry
pull/81282/head
Vlad Glagolev 1 year ago committed by GitHub
parent b771e59793
commit 894c339df8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- "``ansible.module_utils.service`` - fix inter-process communication in ``daemonize()``"

@ -207,17 +207,19 @@ def daemonize(module, cmd):
p = subprocess.Popen(run_cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=lambda: os.close(pipe[1]))
fds = [p.stdout, p.stderr]
# loop reading output till its done
# loop reading output till it is done
output = {p.stdout: b(""), p.stderr: b("")}
while fds:
rfd, wfd, efd = select.select(fds, [], fds, 1)
if (rfd + wfd + efd) or p.poll():
if (rfd + wfd + efd) or p.poll() is None:
for out in list(fds):
if out in rfd:
data = os.read(out.fileno(), chunk)
if not data:
fds.remove(out)
output[out] += b(data)
output[out] += data
else:
break
# even after fds close, we might want to wait for pid to die
p.wait()
@ -246,7 +248,7 @@ def daemonize(module, cmd):
data = os.read(pipe[0], chunk)
if not data:
break
return_data += b(data)
return_data += data
# Note: no need to specify encoding on py3 as this module sends the
# pickle to itself (thus same python interpreter so we aren't mixing

Loading…
Cancel
Save