Skip to content

Commit

Permalink
drivers/clone{,-outlet}.c: parse_args(): add a skip_out label to log …
Browse files Browse the repository at this point in the history
…ignored socket protocol line details

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Sep 10, 2024
1 parent bda11a8 commit cd6955b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
26 changes: 22 additions & 4 deletions drivers/clone-outlet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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")) {
Expand All @@ -105,7 +105,7 @@ static int parse_args(size_t numargs, char **arg)
}

if (numargs < 2) {
return 0;
goto skip_out;
}

/* DELINFO <var> */
Expand All @@ -115,7 +115,7 @@ static int parse_args(size_t numargs, char **arg)
}

if (numargs < 3) {
return 0;
goto skip_out;
}

/* SETINFO <varname> <value> */
Expand Down Expand Up @@ -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 ? "<empty>" : buf);
}

return 0;
}

Expand Down
29 changes: 23 additions & 6 deletions drivers/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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? */
Expand All @@ -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")) {
Expand All @@ -107,7 +106,7 @@ static int parse_args(size_t numargs, char **arg)
}

if (numargs < 2) {
return 0;
goto skip_out;
}

/* DELINFO <var> */
Expand All @@ -117,7 +116,7 @@ static int parse_args(size_t numargs, char **arg)
}

if (numargs < 3) {
return 0;
goto skip_out;
}

/* SETINFO <varname> <value> */
Expand Down Expand Up @@ -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 ? "<empty>" : buf);
}

return 0;
}

Expand Down

0 comments on commit cd6955b

Please sign in to comment.