From cd6955b9ddeb957d986350efcdae1c8a8006261b Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 10 Sep 2024 16:56:41 +0200 Subject: [PATCH] drivers/clone{,-outlet}.c: parse_args(): add a skip_out label to log ignored socket protocol line details Signed-off-by: Jim Klimov --- drivers/clone-outlet.c | 26 ++++++++++++++++++++++---- drivers/clone.c | 29 +++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/drivers/clone-outlet.c b/drivers/clone-outlet.c index 0a07201244..5399c81a4c 100644 --- a/drivers/clone-outlet.c +++ b/drivers/clone-outlet.c @@ -29,7 +29,7 @@ #endif #define DRIVER_NAME "Clone outlet UPS driver" -#define DRIVER_VERSION "0.05" +#define DRIVER_VERSION "0.06" /* driver description structure */ upsdrv_info_t upsdrv_info = { @@ -80,7 +80,7 @@ static OVERLAPPED read_overlapped; static int parse_args(size_t numargs, char **arg) { if (numargs < 1) { - return 0; + goto skip_out; } if (!strcasecmp(arg[0], "PONG")) { @@ -105,7 +105,7 @@ static int parse_args(size_t numargs, char **arg) } if (numargs < 2) { - return 0; + goto skip_out; } /* DELINFO */ @@ -115,7 +115,7 @@ static int parse_args(size_t numargs, char **arg) } if (numargs < 3) { - return 0; + goto skip_out; } /* SETINFO */ @@ -147,6 +147,24 @@ static int parse_args(size_t numargs, char **arg) return 1; } +skip_out: + if (nut_debug_level > 0) { + char buf[LARGEBUF]; + size_t i; + int len = -1; + + memset(buf, 0, sizeof(buf)); + for (i = 0; i < numargs; i++) { + len = snprintfcat(buf, sizeof(buf), "[%s] ", arg[i]); + } + if (len > 0) { + buf[len - 1] = '\0'; + } + + upsdebugx(3, "%s: ignored protocol line with %" PRIuSIZE " keyword(s): %s", + __func__, numargs, numargs < 1 ? "" : buf); + } + return 0; } diff --git a/drivers/clone.c b/drivers/clone.c index 1706ebe757..2eef866c88 100644 --- a/drivers/clone.c +++ b/drivers/clone.c @@ -31,7 +31,7 @@ #endif #define DRIVER_NAME "Clone UPS driver" -#define DRIVER_VERSION "0.05" +#define DRIVER_VERSION "0.06" /* driver description structure */ upsdrv_info_t upsdrv_info = { @@ -65,8 +65,7 @@ static int dumpdone = 0, online = 1, outlet = 1; static long offdelay = 120, ondelay = 30; static PCONF_CTX_t sock_ctx; -static time_t last_poll = 0, last_heard = 0, - last_ping = 0; +static time_t last_poll = 0, last_heard = 0, last_ping = 0; #ifndef WIN32 /* TODO: Why not built in WIN32? */ @@ -82,7 +81,7 @@ static int instcmd(const char *cmdname, const char *extra); static int parse_args(size_t numargs, char **arg) { if (numargs < 1) { - return 0; + goto skip_out; } if (!strcasecmp(arg[0], "PONG")) { @@ -107,7 +106,7 @@ static int parse_args(size_t numargs, char **arg) } if (numargs < 2) { - return 0; + goto skip_out; } /* DELINFO */ @@ -117,7 +116,7 @@ static int parse_args(size_t numargs, char **arg) } if (numargs < 3) { - return 0; + goto skip_out; } /* SETINFO */ @@ -163,6 +162,24 @@ static int parse_args(size_t numargs, char **arg) return 1; } +skip_out: + if (nut_debug_level > 0) { + char buf[LARGEBUF]; + size_t i; + int len = -1; + + memset(buf, 0, sizeof(buf)); + for (i = 0; i < numargs; i++) { + len = snprintfcat(buf, sizeof(buf), "[%s] ", arg[i]); + } + if (len > 0) { + buf[len - 1] = '\0'; + } + + upsdebugx(3, "%s: ignored protocol line with %" PRIuSIZE " keyword(s): %s", + __func__, numargs, numargs < 1 ? "" : buf); + } + return 0; }