Imported Upstream version 2.6.1
This commit is contained in:
parent
459aaf9392
commit
a367d9bc54
178 changed files with 4651 additions and 3279 deletions
|
|
@ -32,7 +32,7 @@
|
|||
#include "state.h"
|
||||
#include "parseconf.h"
|
||||
|
||||
static int sockfd = -1, stale = 1, alarm_active = 0;
|
||||
static int sockfd = -1, stale = 1, alarm_active = 0, ignorelb = 0;
|
||||
static char *sockfn = NULL;
|
||||
static char status_buf[ST_MAX_VALUE_LEN], alarm_buf[ST_MAX_VALUE_LEN];
|
||||
static st_tree_t *dtree_root = NULL;
|
||||
|
|
@ -223,8 +223,11 @@ static void sock_connect(int sock)
|
|||
int fd, ret;
|
||||
conn_t *conn;
|
||||
struct sockaddr_un sa;
|
||||
#if defined(__hpux) && !defined(_XOPEN_SOURCE_EXTENDED)
|
||||
int salen;
|
||||
#else
|
||||
socklen_t salen;
|
||||
|
||||
#endif
|
||||
salen = sizeof(sa);
|
||||
fd = accept(sock, (struct sockaddr *) &sa, &salen);
|
||||
|
||||
|
|
@ -639,7 +642,12 @@ void dstate_setflags(const char *var, int flags)
|
|||
sttmp = state_tree_find(dtree_root, var);
|
||||
|
||||
if (!sttmp) {
|
||||
upslogx(LOG_ERR, "dstate_setflags: base variable (%s) does not exist", var);
|
||||
upslogx(LOG_ERR, "%s: base variable (%s) does not exist", __func__, var);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sttmp->flags & ST_FLAG_IMMUTABLE) {
|
||||
upslogx(LOG_WARNING, "%s: base variable (%s) is immutable", __func__, var);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -792,12 +800,21 @@ int dstate_is_stale(void)
|
|||
/* clean out the temp space for a new pass */
|
||||
void status_init(void)
|
||||
{
|
||||
if (dstate_getinfo("driver.flag.ignorelb")) {
|
||||
ignorelb = 1;
|
||||
}
|
||||
|
||||
memset(status_buf, 0, sizeof(status_buf));
|
||||
}
|
||||
|
||||
/* add a status element */
|
||||
void status_set(const char *buf)
|
||||
{
|
||||
if (ignorelb && !strcasecmp(buf, "LB")) {
|
||||
upsdebugx(2, "%s: ignoring LB flag from device", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
/* separate with a space if multiple elements are present */
|
||||
if (strlen(status_buf) > 0) {
|
||||
snprintfcat(status_buf, sizeof(status_buf), " %s", buf);
|
||||
|
|
@ -809,6 +826,31 @@ void status_set(const char *buf)
|
|||
/* write the status_buf into the externally visible dstate storage */
|
||||
void status_commit(void)
|
||||
{
|
||||
while (ignorelb) {
|
||||
const char *val, *low;
|
||||
|
||||
val = dstate_getinfo("battery.charge");
|
||||
low = dstate_getinfo("battery.charge.low");
|
||||
|
||||
if (val && low && (strtol(val, NULL, 10) < strtol(low, NULL, 10))) {
|
||||
snprintfcat(status_buf, sizeof(status_buf), " LB");
|
||||
upsdebugx(2, "%s: appending LB flag [charge '%s' below '%s']", __func__, val, low);
|
||||
break;
|
||||
}
|
||||
|
||||
val = dstate_getinfo("battery.runtime");
|
||||
low = dstate_getinfo("battery.runtime.low");
|
||||
|
||||
if (val && low && (strtol(val, NULL, 10) < strtol(low, NULL, 10))) {
|
||||
snprintfcat(status_buf, sizeof(status_buf), " LB");
|
||||
upsdebugx(2, "%s: appending LB flag [runtime '%s' below '%s']", __func__, val, low);
|
||||
break;
|
||||
}
|
||||
|
||||
/* LB condition not detected */
|
||||
break;
|
||||
}
|
||||
|
||||
if (alarm_active) {
|
||||
dstate_setinfo("ups.status", "ALARM %s", status_buf);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue