From 59acc68ce8c67e641087168848cc8a33ea94ce10 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Tue, 19 Nov 2024 14:36:49 +0100 Subject: [PATCH] drivers/main.c: do_loop_shutdown_commands(): shortcut for "shutdown.default" support [#2670] Signed-off-by: Jim Klimov --- drivers/main.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/main.c b/drivers/main.c index c9063570b3..63abece7cd 100644 --- a/drivers/main.c +++ b/drivers/main.c @@ -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; }