From 91f94fb59d2ec3e69ff98649094f838c6d81601b Mon Sep 17 00:00:00 2001 From: Val Date: Fri, 22 Sep 2023 06:41:30 -0700 Subject: [PATCH] Daemonize follow-up fixes (#81584) * Ensure binary data transmission in daemonize * Add changelog fragment --- changelogs/fragments/81584-daemonize-follow-up-fixes.yml | 2 ++ lib/ansible/module_utils/service.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/81584-daemonize-follow-up-fixes.yml diff --git a/changelogs/fragments/81584-daemonize-follow-up-fixes.yml b/changelogs/fragments/81584-daemonize-follow-up-fixes.yml new file mode 100644 index 00000000000..5842a0a37ca --- /dev/null +++ b/changelogs/fragments/81584-daemonize-follow-up-fixes.yml @@ -0,0 +1,2 @@ +bugfixes: + - "``ansible.module_utils.service`` - ensure binary data transmission in ``daemonize()``" diff --git a/lib/ansible/module_utils/service.py b/lib/ansible/module_utils/service.py index 075adfd9e8e..e79f40edbd3 100644 --- a/lib/ansible/module_utils/service.py +++ b/lib/ansible/module_utils/service.py @@ -215,9 +215,10 @@ def daemonize(module, cmd): for out in list(fds): if out in rfd: data = os.read(out.fileno(), chunk) - if not data: + if data: + output[out] += to_bytes(data, errors=errors) + else: fds.remove(out) - output[out] += data else: break @@ -248,7 +249,7 @@ def daemonize(module, cmd): data = os.read(pipe[0], chunk) if not data: break - return_data += data + return_data += to_bytes(data, errors=errors) # 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