From 8e612b9e0e10ba78a8ae4441ecd1f2d2bf1347a3 Mon Sep 17 00:00:00 2001 From: John Date: Fri, 6 Jan 2023 12:06:12 +0100 Subject: [PATCH] add option to exit non-zero on non-success response from ebusd (fixes #782) --- ChangeLog.md | 2 ++ src/tools/ebusctl.cpp | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 49677cde..f49c8830 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -9,6 +9,7 @@ * fix for older SSL libraries not automatically retrying if necessary * fix enhanced side data transfer from device to host * fix for fast participants starting immediately after own SYN at the end of a sent command +* add a single retry when initial config location check fails ## Features * add support for setting visual ping, IP gateway, MAC from ID, and variant to ebuspicloader @@ -16,6 +17,7 @@ * add yes/no values and writable heating curve to Home Assistant MQTT discovery integration * add device version to update check and switch to Home Assistant update integration for current update check and additionally for device * add preferred language support to web services and use it instead of default LANG environment with fallback to German +* add option to exit non-zero on non-success response from ebusd to ebusctl # 22.4 (2022-09-18) diff --git a/src/tools/ebusctl.cpp b/src/tools/ebusctl.cpp index ea2642f8..d076b57f 100755 --- a/src/tools/ebusctl.cpp +++ b/src/tools/ebusctl.cpp @@ -45,6 +45,7 @@ struct options { const char* server; //!< ebusd server host (name or ip) [localhost] uint16_t port; //!< ebusd server port [8888] uint16_t timeout; //!< ebusd connect/send/receive timeout + bool errorResponse; //!< non-zero exit on error response char* const *args; //!< arguments to pass to ebusd unsigned int argCount; //!< number of arguments to pass to ebusd @@ -54,9 +55,10 @@ struct options { static struct options opt = { "localhost", // server 8888, // port - 60, // timeout + 60, // timeout + false, // non-zero exit on error response - nullptr, // args + nullptr, // args 0 // argCount }; @@ -83,6 +85,7 @@ static const struct argp_option argpoptions[] = { {"port", 'p', "PORT", 0, "Connect to " PACKAGE " on PORT [8888]", 0 }, {"timeout", 't', "SECS", 0, "Timeout for connecting to/receiving from " PACKAGE ", 0 for none [60]", 0 }, + {"error", 'e', nullptr, 0, "Exit non-zero if the connection was fine but the response indicates non-success"}, {nullptr, 0, nullptr, 0, nullptr, 0 }, }; @@ -122,6 +125,9 @@ error_t parse_opt(int key, char *arg, struct argp_state *state) { } opt->timeout = (uint16_t)value; break; + case 'e': // --error + opt->errorResponse = true; + break; case ARGP_KEY_ARGS: opt->args = state->argv + state->next; opt->argCount = state->argc - state->next; @@ -332,8 +338,12 @@ bool connect(const char* host, uint16_t port, uint16_t timeout, char* const *arg } } } else { - cout << fetchData(socket, listening, timeout, errored); + string response = fetchData(socket, listening, timeout, errored); + cout << response; cout.flush(); + if (errored || (opt.errorResponse && response.substr(0, 4) == "ERR:")) { + ret = false; + } } } } while (!errored && !once && !cin.eof());