Browse Source

working version

master
Olaf Rempel 10 years ago
parent
commit
5cace6aad3
2 changed files with 15 additions and 6 deletions
  1. 11
    5
      daemon/alix-usvd.c
  2. 4
    1
      daemon/unixsocket.c

+ 11
- 5
daemon/alix-usvd.c View File

@@ -44,7 +44,7 @@
#define DEFAULT_LOGFILE "alix-usvd.log"
#define DEFAULT_PIDFILE "alix-usvd.pid"
#define DEFAULT_SOCKET "alix-usvd.sock"
#define SENDMAIL "/usr/sbin/sendmail"
#define SENDMAIL "/usr/sbin/sendmail -t"

enum {
REG_STATUS = 0x00,
@@ -163,31 +163,37 @@ static int check_thresholds(void)
int changed = 0;

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);
changed = 1;
}

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);
changed = 1;
}

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);
changed = 1;
}

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);
changed = 1;
}

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);
changed = 1;
}

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);
changed = 1;
}
@@ -252,8 +258,8 @@ static void alix_state_change(int old_state, int new_state)
static int mail_data;

if (mail_data == 0) {
mail_from = config_get_string("global", "mail-from", NULL);
mail_to = config_get_string("global", "mail-to", NULL);
mail_from = config_get_string("alerts", "mail-from", NULL);
mail_to = config_get_string("alerts", "mail-to", NULL);
mail_data = 1;
}

@@ -291,14 +297,14 @@ static int unix_read_cb(int fd, void *privdata)
int new_state = str2state(buf);
if (new_state != -1) {
if (i2c_smbus_write_word_data(dev, REG_STATUS, new_state) == 0) {
alix_state_change(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));
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);
int adc_ibat = i2c_smbus_read_word_data(dev, REG_CURRENT);
int adc_ubat = i2c_smbus_read_word_data(dev, REG_UBAT);

+ 4
- 1
daemon/unixsocket.c View File

@@ -24,6 +24,7 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/stat.h>
#include <errno.h>

#include "logging.h"

@@ -45,11 +46,13 @@ int unix_listen(const char *filename)
strncpy(addr.sun_path, filename, sizeof(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()");
return -1;
}

errno = 0;

mode_t old_umask = umask(0077);
int ret = bind(sockfd, (struct sockaddr *) &addr, len);
umask(old_umask);

Loading…
Cancel
Save