From 7ab26135c2410422ca17f87efa278049146515da Mon Sep 17 00:00:00 2001 From: Hemna Date: Mon, 11 Jan 2021 14:13:20 -0500 Subject: [PATCH] Fixed fortune plugin failures On alpine containers the fortune options aren't all available and we were silently failing. Updated the fortune plugin to capture shell failures. --- aprsd/plugins/fortune.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/aprsd/plugins/fortune.py b/aprsd/plugins/fortune.py index 52e59e1..d66255c 100644 --- a/aprsd/plugins/fortune.py +++ b/aprsd/plugins/fortune.py @@ -24,14 +24,17 @@ class FortunePlugin(plugin.APRSDPluginBase): return reply try: - process = subprocess.Popen( - [fortune_path, "-s", "-n 60"], - stdout=subprocess.PIPE, + cmnd = [fortune_path, "-s", "-n 60"] + command = " ".join(cmnd) + output = subprocess.check_output( + command, + shell=True, + timeout=3, + universal_newlines=True, ) - reply = process.communicate()[0] - reply = reply.decode(errors="ignore").rstrip() - except Exception as ex: - reply = "Fortune command failed '{}'".format(ex) - LOG.error(reply) + except subprocess.CalledProcessError as ex: + reply = "Fortune command failed '{}'".format(ex.output) + else: + reply = output return reply