working version
This commit is contained in:
parent
24ff8bca57
commit
5cace6aad3
@ -44,7 +44,7 @@
|
|||||||
#define DEFAULT_LOGFILE "alix-usvd.log"
|
#define DEFAULT_LOGFILE "alix-usvd.log"
|
||||||
#define DEFAULT_PIDFILE "alix-usvd.pid"
|
#define DEFAULT_PIDFILE "alix-usvd.pid"
|
||||||
#define DEFAULT_SOCKET "alix-usvd.sock"
|
#define DEFAULT_SOCKET "alix-usvd.sock"
|
||||||
#define SENDMAIL "/usr/sbin/sendmail"
|
#define SENDMAIL "/usr/sbin/sendmail -t"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
REG_STATUS = 0x00,
|
REG_STATUS = 0x00,
|
||||||
@ -163,31 +163,37 @@ static int check_thresholds(void)
|
|||||||
int changed = 0;
|
int changed = 0;
|
||||||
|
|
||||||
if (device.uin_loss != config.uin_loss) {
|
if (device.uin_loss != config.uin_loss) {
|
||||||
|
log_print(LOG_INFO, "update UIN_LOSS: %d => %d", device.uin_loss, config.uin_loss);
|
||||||
i2c_smbus_write_word_data(dev, REG_UIN_LOSS, config.uin_loss);
|
i2c_smbus_write_word_data(dev, REG_UIN_LOSS, config.uin_loss);
|
||||||
changed = 1;
|
changed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device.uin_restore != config.uin_restore) {
|
if (device.uin_restore != config.uin_restore) {
|
||||||
|
log_print(LOG_INFO, "update UIN_RESTORE: %d => %d", device.uin_restore, config.uin_restore);
|
||||||
i2c_smbus_write_word_data(dev, REG_UIN_RESTORE, config.uin_restore);
|
i2c_smbus_write_word_data(dev, REG_UIN_RESTORE, config.uin_restore);
|
||||||
changed = 1;
|
changed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device.ubat_full != config.ubat_full) {
|
if (device.ubat_full != config.ubat_full) {
|
||||||
|
log_print(LOG_INFO, "update UBAT_FULL: %d => %d", device.ubat_full, config.ubat_full);
|
||||||
i2c_smbus_write_word_data(dev, REG_UBAT_FULL, config.ubat_full);
|
i2c_smbus_write_word_data(dev, REG_UBAT_FULL, config.ubat_full);
|
||||||
changed = 1;
|
changed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device.ubat_low != config.ubat_low) {
|
if (device.ubat_low != config.ubat_low) {
|
||||||
|
log_print(LOG_INFO, "update UBAT_LOW: %d => %d", device.ubat_low, config.ubat_low);
|
||||||
i2c_smbus_write_word_data(dev, REG_UBAT_LOW, config.ubat_low);
|
i2c_smbus_write_word_data(dev, REG_UBAT_LOW, config.ubat_low);
|
||||||
changed = 1;
|
changed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device.ubat_critical != config.ubat_critical) {
|
if (device.ubat_critical != config.ubat_critical) {
|
||||||
|
log_print(LOG_INFO, "update UBAT_CRIT: %d => %d", device.ubat_critical, config.ubat_critical);
|
||||||
i2c_smbus_write_word_data(dev, REG_UBAT_CRIT, config.ubat_critical);
|
i2c_smbus_write_word_data(dev, REG_UBAT_CRIT, config.ubat_critical);
|
||||||
changed = 1;
|
changed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device.ibat_full != config.ibat_full) {
|
if (device.ibat_full != config.ibat_full) {
|
||||||
|
log_print(LOG_INFO, "update IBAT_FULL: %d => %d", device.ibat_full, config.ibat_full);
|
||||||
i2c_smbus_write_word_data(dev, REG_IBAT_FULL, config.ibat_full);
|
i2c_smbus_write_word_data(dev, REG_IBAT_FULL, config.ibat_full);
|
||||||
changed = 1;
|
changed = 1;
|
||||||
}
|
}
|
||||||
@ -252,8 +258,8 @@ static void alix_state_change(int old_state, int new_state)
|
|||||||
static int mail_data;
|
static int mail_data;
|
||||||
|
|
||||||
if (mail_data == 0) {
|
if (mail_data == 0) {
|
||||||
mail_from = config_get_string("global", "mail-from", NULL);
|
mail_from = config_get_string("alerts", "mail-from", NULL);
|
||||||
mail_to = config_get_string("global", "mail-to", NULL);
|
mail_to = config_get_string("alerts", "mail-to", NULL);
|
||||||
mail_data = 1;
|
mail_data = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,14 +297,14 @@ static int unix_read_cb(int fd, void *privdata)
|
|||||||
int new_state = str2state(buf);
|
int new_state = str2state(buf);
|
||||||
if (new_state != -1) {
|
if (new_state != -1) {
|
||||||
if (i2c_smbus_write_word_data(dev, REG_STATUS, new_state) == 0) {
|
if (i2c_smbus_write_word_data(dev, REG_STATUS, new_state) == 0) {
|
||||||
|
alix_state_change(alix_state, new_state);
|
||||||
alix_state = new_state;
|
alix_state = new_state;
|
||||||
log_print(LOG_INFO, "set state to %s", state2str(alix_state));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int len = snprintf(buf, sizeof(buf), "%s", state2str(alix_state));
|
int len = snprintf(buf, sizeof(buf), "%s", state2str(alix_state));
|
||||||
write(fd, buf, len);
|
write(fd, buf, len);
|
||||||
|
|
||||||
} else if (strncmp(buf, "status", 6) == 0) {
|
} else if (strncasecmp(buf, "status", 6) == 0) {
|
||||||
new_state = i2c_smbus_read_word_data(dev, REG_STATUS);
|
new_state = i2c_smbus_read_word_data(dev, REG_STATUS);
|
||||||
int adc_ibat = i2c_smbus_read_word_data(dev, REG_CURRENT);
|
int adc_ibat = i2c_smbus_read_word_data(dev, REG_CURRENT);
|
||||||
int adc_ubat = i2c_smbus_read_word_data(dev, REG_UBAT);
|
int adc_ubat = i2c_smbus_read_word_data(dev, REG_UBAT);
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
@ -45,11 +46,13 @@ int unix_listen(const char *filename)
|
|||||||
strncpy(addr.sun_path, filename, sizeof(addr.sun_path));
|
strncpy(addr.sun_path, filename, sizeof(addr.sun_path));
|
||||||
int len = sizeof(addr.sun_family) + strlen(addr.sun_path);
|
int len = sizeof(addr.sun_family) + strlen(addr.sun_path);
|
||||||
|
|
||||||
if (unlink(addr.sun_path) == -1) {
|
if (unlink(addr.sun_path) == -1 && errno != ENOENT) {
|
||||||
log_print(LOG_ERROR, "unix_listen: unlink()");
|
log_print(LOG_ERROR, "unix_listen: unlink()");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
|
||||||
mode_t old_umask = umask(0077);
|
mode_t old_umask = umask(0077);
|
||||||
int ret = bind(sockfd, (struct sockaddr *) &addr, len);
|
int ret = bind(sockfd, (struct sockaddr *) &addr, len);
|
||||||
umask(old_umask);
|
umask(old_umask);
|
||||||
|
Loading…
Reference in New Issue
Block a user