Skip to content

Commit

Permalink
Cancel any pending shutdowns before sending a new shutdown command
Browse files Browse the repository at this point in the history
Fossil-ID: SVN r1756
  • Loading branch information
arjendekorte committed Jan 27, 2009
1 parent 2fc456c commit 0eef5be
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
43 changes: 27 additions & 16 deletions drivers/blazer.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,16 @@ static int blazer_instcmd(const char *cmdname, const char *extra)

snprintf(buf, sizeof(buf), "%s", instcmd[i].ups);

if (blazer_command(buf, buf, sizeof(buf)) == 0) {
upslogx(LOG_INFO, "instcmd: command [%s] handled", cmdname);
return STAT_INSTCMD_HANDLED;
/*
* If a command is invalid, it will be echoed back
*/
if (blazer_command(buf, buf, sizeof(buf)) > 0) {
upslogx(LOG_ERR, "instcmd: command [%s] failed", cmdname);
return STAT_INSTCMD_FAILED;
}

upslogx(LOG_ERR, "instcmd: command [%s] failed", cmdname);
return STAT_INSTCMD_FAILED;
upslogx(LOG_INFO, "instcmd: command [%s] handled", cmdname);
return STAT_INSTCMD_HANDLED;
}

if (!strcasecmp(cmdname, "shutdown.return")) {
Expand Down Expand Up @@ -418,14 +421,16 @@ static int blazer_instcmd(const char *cmdname, const char *extra)
return STAT_INSTCMD_UNKNOWN;
}

if (blazer_command(buf, buf, sizeof(buf)) == 0) {
upslogx(LOG_INFO, "instcmd: command [%s] handled", cmdname);
return STAT_INSTCMD_HANDLED;
/*
* If a command is invalid, it will be echoed back
*/
if (blazer_command(buf, buf, sizeof(buf)) > 0) {
upslogx(LOG_ERR, "instcmd: command [%s] failed", cmdname);
return STAT_INSTCMD_FAILED;
}

upslogx(LOG_ERR, "instcmd: command [%s] failed", cmdname);
return STAT_INSTCMD_FAILED;

upslogx(LOG_INFO, "instcmd: command [%s] handled", cmdname);
return STAT_INSTCMD_HANDLED;
}


Expand Down Expand Up @@ -590,12 +595,18 @@ void upsdrv_shutdown(void)
{
int retry;

for (retry = 0; retry < MAXTRIES; retry++) {
for (retry = 1; retry <= MAXTRIES; retry++) {

if (blazer_instcmd("shutdown.return", NULL) == STAT_INSTCMD_HANDLED) {
return;
if (blazer_instcmd("shutdown.stop", NULL) != STAT_INSTCMD_HANDLED) {
continue;
}
}

upsdebugx(2, "Shutdown failed after %d retries!", retry);
if (blazer_instcmd("shutdown.return", NULL) != STAT_INSTCMD_HANDLED) {
continue;
}

fatalx(EXIT_SUCCESS, "Shutting down in %d seconds", offdelay);
}

fatalx(EXIT_FAILURE, "Shutdown failed!");
}
2 changes: 1 addition & 1 deletion drivers/blazer_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static int phoenix_command(const char *cmd, char *buf, size_t buflen)

if (ret <= 0) {
upsdebugx(3, "read: %s", ret ? usb_strerror() : "timeout");
return ret;
return 0;
}
}

Expand Down

0 comments on commit 0eef5be

Please sign in to comment.