Skip to content

Commit

Permalink
drivers/main.c: do_loop_shutdown_commands(): shortcut for "shutdown.d…
Browse files Browse the repository at this point in the history
…efault" support [networkupstools#2670]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Nov 19, 2024
1 parent 7b52ab9 commit 59acc68
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions drivers/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,28 @@ int do_loop_shutdown_commands(const char *sdcmds, char **cmdused) {

if (upsh.instcmd == NULL) {
upsdebugx(1, "This driver does not implement INSTCMD support");

/* ...but the default one we can short-circuit without
* registered INSTCMDs (FIXME: loop detection/protection):
*/
s = strstr(sdcmds, "shutdown.default");
if (s) {
/* check this is really a sub-string */
size_t cmdlen = strlen("shutdown.default");
if (
(s == sdcmds || *(s-1) == ',') &&
(s[cmdlen] == '\0' || s[cmdlen] == ',')
) {
upsdebugx(1, "Handle 'shutdown.default' directly, "
"ignore other `sdcommands` (if any): %s",
sdcmds);
upsdrv_shutdown();
cmdret = STAT_INSTCMD_HANDLED;
/* commented below */
if (cmdused && !(*cmdused))
*cmdused = xstrdup("shutdown.default");
}
}
goto done;
}

Expand Down

0 comments on commit 59acc68

Please sign in to comment.