Skip to content

Commit

Permalink
Revert "drivers/main.{c,h}, drivers/dstate.c: introduce main_instcmd_…
Browse files Browse the repository at this point in the history
…fallback() so drivers might implement their own "shutdown.default" at will [networkupstools#2670]"

This reverts commit 25250b0:
too messy in logs where driver.instcmd() think they are last in stack.

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Nov 19, 2024
1 parent d0b42c4 commit fbef5c5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 53 deletions.
25 changes: 7 additions & 18 deletions drivers/dstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,26 +847,15 @@ static int sock_arg(conn_t *conn, size_t numarg, char **arg)
if (upsh.instcmd) {
ret = upsh.instcmd(cmdname, cmdparam);

if (ret != STAT_INSTCMD_UNKNOWN) {
/* send back execution result if requested */
if (cmdid)
send_tracking(conn, cmdid, ret);

/* The command was handled, status is a separate consideration */
return 1;
} /* else try other handler(s) */
} /* else try other handler(s) */
/* send back execution result if requested */
if (cmdid)
send_tracking(conn, cmdid, ret);

/* Finally try the fallback handler shared by all drivers */
ret = main_instcmd_fallback(cmdname, cmdparam, conn);
/* send back execution result if requested */
if (cmdid)
send_tracking(conn, cmdid, ret);
/* The command was handled, status is a separate consideration */
return 1;
}

if (ret == STAT_INSTCMD_UNKNOWN)
upslogx(LOG_NOTICE,
"Got INSTCMD '%s', but driver lacks a handler",
NUT_STRARG(cmdname));
upslogx(LOG_NOTICE, "Got INSTCMD, but driver lacks a handler");
return 1;
}

Expand Down
28 changes: 2 additions & 26 deletions drivers/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,9 +947,8 @@ int upsdrv_shutdown_sdcommands_or_default(const char *sdcmds_default, char **cmd
return sdret;
}

/* handle instant commands common for all drivers - fallback for common
* command names that could be implemented in a driver but were not */
int main_instcmd_fallback(const char *cmdname, const char *extra, conn_t *conn) {
/* handle instant commands common for all drivers */
int main_instcmd(const char *cmdname, const char *extra, conn_t *conn) {
char buf[SMALLBUF];
if (conn)
#ifndef WIN32
Expand Down Expand Up @@ -981,29 +980,6 @@ int main_instcmd_fallback(const char *cmdname, const char *extra, conn_t *conn)
return STAT_INSTCMD_HANDLED;
}

/* By default, the driver-specific values are
* unknown to shared standard handler */
upsdebugx(2, "shared %s() does not handle command %s, "
"proceeding to driver-specific handler",
__func__, cmdname);
return STAT_INSTCMD_UNKNOWN;
}

/* handle instant commands common for all drivers */
int main_instcmd(const char *cmdname, const char *extra, conn_t *conn) {
char buf[SMALLBUF];
if (conn)
#ifndef WIN32
snprintf(buf, sizeof(buf), "socket %d", conn->fd);
#else
snprintf(buf, sizeof(buf), "handle %p", conn->fd);
#endif
else
snprintf(buf, sizeof(buf), "(null)");

upsdebugx(2, "entering main_instcmd(%s, %s) for [%s] on %s",
cmdname, extra, NUT_STRARG(upsname), buf);

if (!strcmp(cmdname, "driver.killpower")) {
/* An implementation of `drivername -k` requested from
* the running and connected driver instance by protocol
Expand Down
4 changes: 0 additions & 4 deletions drivers/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ int upsdrv_shutdown_sdcommands_or_default(const char *sdcmds_default, char **cmd
*/
int main_instcmd(const char *cmdname, const char *extra, conn_t *conn);

/* handle instant commands common for all drivers - fallback for common
* command names that could be implemented in a driver but were not */
int main_instcmd_fallback(const char *cmdname, const char *extra, conn_t *conn);

/* handle setting variables common for all drivers
* (returns STAT_SET_* state values per enum in upshandler.h)
*/
Expand Down
5 changes: 0 additions & 5 deletions drivers/skel.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ void upsdrv_shutdown(void)
/*
static int instcmd(const char *cmdname, const char *extra)
{
if (!strcasecmp(cmdname, "shutdown.default")) {
// optional custom implementation - but we
// prefer to code upsdrv_shutdown() directly
}
if (!strcasecmp(cmdname, "test.battery.stop")) {
ser_send_buf(upsfd, ...);
return STAT_INSTCMD_HANDLED;
Expand Down

0 comments on commit fbef5c5

Please sign in to comment.