Imported Upstream version 2.7.1

This commit is contained in:
Laurent Bigonville 2013-11-24 16:00:12 +01:00
parent a1fa151fc7
commit 0121794af9
451 changed files with 41339 additions and 10887 deletions

View file

@ -407,6 +407,8 @@ static int blazer_instcmd(const char *cmdname, const char *extra)
char buf[SMALLBUF] = "";
int i;
upslogx(LOG_INFO, "instcmd(%s, %s)", cmdname, extra ? extra : "[NULL]");
for (i = 0; instcmd[i].cmd; i++) {
if (strcasecmp(cmdname, instcmd[i].cmd)) {
@ -417,10 +419,14 @@ static int blazer_instcmd(const char *cmdname, const char *extra)
/*
* If a command is invalid, it will be echoed back
* As an exception, Best UPS units will report "ACK" in case of success!
* Other UPSes will reply "(ACK" in case of success.
*/
if (blazer_command(buf, buf, sizeof(buf)) > 0) {
upslogx(LOG_ERR, "instcmd: command [%s] failed", cmdname);
return STAT_INSTCMD_FAILED;
if (strncmp(buf, "ACK", 3) && strncmp(buf, "(ACK", 4)) {
upslogx(LOG_ERR, "instcmd: command [%s] failed", cmdname);
return STAT_INSTCMD_FAILED;
}
}
upslogx(LOG_INFO, "instcmd: command [%s] handled", cmdname);
@ -428,28 +434,56 @@ static int blazer_instcmd(const char *cmdname, const char *extra)
}
if (!strcasecmp(cmdname, "shutdown.return")) {
/*
* Sn: Shutdown after n minutes and then turn on when mains is back
* SnRm: Shutdown after n minutes and then turn on after m minutes
* Accepted values for n: .2 -> .9 , 01 -> 10
* Accepted values for m: 0001 -> 9999
* Note: "S01R0001" and "S01R0002" may not work on early (GE)
* firmware versions. The failure mode is that the UPS turns
* off and never returns. The fix is to push the return value
* up by 2, i.e. S01R0003, and it will return online properly.
* (thus the default of ondelay=3 mins)
*/
if (offdelay < 60) {
if (ondelay == 0) {
if (offdelay < 60) {
snprintf(buf, sizeof(buf), "S.%d\r", offdelay / 6);
} else {
snprintf(buf, sizeof(buf), "S%02d\r", offdelay / 60);
}
} else if (offdelay < 60) {
snprintf(buf, sizeof(buf), "S.%dR%04d\r", offdelay / 6, ondelay);
} else {
snprintf(buf, sizeof(buf), "S%02dR%04d\r", offdelay / 60, ondelay);
}
} else if (!strcasecmp(cmdname, "shutdown.stayoff")) {
/*
* SnR0000
* Shutdown after n minutes and stay off
* Accepted values for n: .2 -> .9 , 01 -> 10
*/
if (offdelay < 60) {
snprintf(buf, sizeof(buf), "S.%dR0000\r", offdelay / 6);
} else {
snprintf(buf, sizeof(buf), "S%02dR0000\r", offdelay / 60);
}
} else if (!strcasecmp(cmdname, "test.battery.start")) {
int delay = extra ? strtol(extra, NULL, 10) : 10;
if ((delay < 0) || (delay > 99)) {
if ((delay < 1) || (delay > 99)) {
upslogx(LOG_ERR, "instcmd: command [%s] failed, delay [%s] out of range", cmdname, extra);
return STAT_INSTCMD_FAILED;
}
@ -462,9 +496,10 @@ static int blazer_instcmd(const char *cmdname, const char *extra)
/*
* If a command is invalid, it will be echoed back.
* As an exception, Best UPS units will report "ACK" in case of success!
* Other UPSes will reply "(ACK" in case of success.
*/
if (blazer_command(buf, buf, sizeof(buf)) > 0) {
if (strncmp(buf, "ACK", 3)) {
if (strncmp(buf, "ACK", 3) && strncmp(buf, "(ACK", 4)) {
upslogx(LOG_ERR, "instcmd: command [%s] failed", cmdname);
return STAT_INSTCMD_FAILED;
}
@ -509,8 +544,8 @@ void blazer_initups(void)
offdelay = strtol(val, NULL, 10);
}
if ((offdelay < 6) || (offdelay > 600)) {
fatalx(EXIT_FAILURE, "Shutdown delay '%d' out of range [6..600]", offdelay);
if ((offdelay < 12) || (offdelay > 600)) {
fatalx(EXIT_FAILURE, "Shutdown delay '%d' out of range [12..600]", offdelay);
}
/* Truncate to nearest setable value */
@ -538,7 +573,7 @@ static void blazer_initbattery(void)
/* If no values were provided by the user in ups.conf, try to guesstimate
* battery.charge, but announce it! */
if ((batt.volt.nom != 1) && (batt.volt.high == -1) && (batt.volt.high == -1)) {
if ((batt.volt.nom != 1) && ((batt.volt.high == -1) || (batt.volt.low == -1))) {
upslogx(LOG_INFO, "No values provided for battery high/low voltages in ups.conf\n");
/* Basic formula, which should cover most cases */
@ -778,17 +813,30 @@ void upsdrv_shutdown(void)
{
int retry;
/* Stop pending shutdowns */
for (retry = 1; retry <= MAXTRIES; retry++) {
if (blazer_instcmd("shutdown.stop", NULL) != STAT_INSTCMD_HANDLED) {
continue;
}
break;
}
if (retry > MAXTRIES) {
upslogx(LOG_NOTICE, "No shutdown pending");
}
/* Shutdown */
for (retry = 1; retry <= MAXTRIES; 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!");