various fixes

This commit is contained in:
Olaf Rempel 2009-06-01 13:51:12 +02:00
parent d8a80d24b9
commit b3d727456e
2 changed files with 14 additions and 14 deletions

View File

@ -44,6 +44,8 @@ pid_t pidfile_check(const char *filename, int remove_stale)
int len = read(fd, buf, sizeof(buf) -1);
buf[len] = '\0';
close(fd);
char *tmp;
pid_t pid = strtol(buf, &tmp, 10);
if (len == 0 || tmp == buf)

View File

@ -91,17 +91,11 @@ static int str2state(char *buf)
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));
if (status != NULL)
state = status->state;
old_state = state;
return state;
}
state = status->state;
if (state == old_state)
return state;
@ -109,20 +103,24 @@ static int usvstate_update(int state, struct usvdev_status *status)
if (mail_to != NULL) {
FILE *mail = popen(SENDMAIL, "w");
if (mail == NULL) {
if (mail != NULL) {
fprintf(mail, "From: %s\n", mail_from);
fprintf(mail, "To: %s\n", mail_to);
fprintf(mail, "Subject: alix-usvd state change: %s => %s\n\n",
state2str(old_state), state2str(state));
fprintf(mail, "Current USV status:\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);
if (status != NULL) {
fprintf(mail, "Current USV status:\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);
}
fprintf(mail, "Faithfully yours, etc.\n");
fclose(mail);
}
}
old_state = 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",
state2str(status.state),
(signed)status.ibat, status.ubat, status.uin);
(short)status.ibat, status.ubat, status.uin);
write(fd, buf, len);
}