various fixes
This commit is contained in:
parent
d8a80d24b9
commit
b3d727456e
@ -44,6 +44,8 @@ pid_t pidfile_check(const char *filename, int remove_stale)
|
|||||||
int len = read(fd, buf, sizeof(buf) -1);
|
int len = read(fd, buf, sizeof(buf) -1);
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
char *tmp;
|
char *tmp;
|
||||||
pid_t pid = strtol(buf, &tmp, 10);
|
pid_t pid = strtol(buf, &tmp, 10);
|
||||||
if (len == 0 || tmp == buf)
|
if (len == 0 || tmp == buf)
|
||||||
|
@ -91,17 +91,11 @@ static int str2state(char *buf)
|
|||||||
|
|
||||||
static int usvstate_update(int state, struct usvdev_status *status)
|
static int usvstate_update(int state, struct usvdev_status *status)
|
||||||
{
|
{
|
||||||
static int old_state = -1;
|
static int old_state;
|
||||||
|
|
||||||
if (status == NULL) {
|
|
||||||
if (state != old_state)
|
|
||||||
log_print(LOG_INFO, "usv state forced to: %s", state2str(state));
|
|
||||||
|
|
||||||
old_state = state;
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (status != NULL)
|
||||||
state = status->state;
|
state = status->state;
|
||||||
|
|
||||||
if (state == old_state)
|
if (state == old_state)
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
@ -109,20 +103,24 @@ static int usvstate_update(int state, struct usvdev_status *status)
|
|||||||
|
|
||||||
if (mail_to != NULL) {
|
if (mail_to != NULL) {
|
||||||
FILE *mail = popen(SENDMAIL, "w");
|
FILE *mail = popen(SENDMAIL, "w");
|
||||||
if (mail == NULL) {
|
if (mail != NULL) {
|
||||||
fprintf(mail, "From: %s\n", mail_from);
|
fprintf(mail, "From: %s\n", mail_from);
|
||||||
fprintf(mail, "To: %s\n", mail_to);
|
fprintf(mail, "To: %s\n", mail_to);
|
||||||
fprintf(mail, "Subject: alix-usvd state change: %s => %s\n\n",
|
fprintf(mail, "Subject: alix-usvd state change: %s => %s\n\n",
|
||||||
state2str(old_state), state2str(state));
|
state2str(old_state), state2str(state));
|
||||||
|
|
||||||
|
if (status != NULL) {
|
||||||
fprintf(mail, "Current USV status:\n");
|
fprintf(mail, "Current USV status:\n");
|
||||||
fprintf(mail, "Ibat: %1.3lf mA\nUbat: %2.3lf V\nUin : %2.3lf V\n\n",
|
fprintf(mail, "Ibat: %1.3lf mA\nUbat: %2.3lf V\nUin : %2.3lf V\n\n",
|
||||||
status->ibat / 1000.0, status->ubat / 1000.0, status->uin / 1000.0);
|
status->ibat / 1000.0, status->ubat / 1000.0, status->uin / 1000.0);
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(mail, "Faithfully yours, etc.\n");
|
fprintf(mail, "Faithfully yours, etc.\n");
|
||||||
fclose(mail);
|
fclose(mail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
old_state = state;
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +147,7 @@ static int unix_read_cb(int fd, void *privdata)
|
|||||||
|
|
||||||
int len = snprintf(buf, sizeof(buf), "%s:%d:%d:%d",
|
int len = snprintf(buf, sizeof(buf), "%s:%d:%d:%d",
|
||||||
state2str(status.state),
|
state2str(status.state),
|
||||||
(signed)status.ibat, status.ubat, status.uin);
|
(short)status.ibat, status.ubat, status.uin);
|
||||||
write(fd, buf, len);
|
write(fd, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user