Browse Source

various fixes

master
Olaf Rempel 10 years ago
parent
commit
b3d727456e
2 changed files with 14 additions and 14 deletions
  1. 2
    0
      daemon/pidfile.c
  2. 12
    14
      daemon/usvstate.c

+ 2
- 0
daemon/pidfile.c View File

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

+ 12
- 14
daemon/usvstate.c View File

@@ -91,17 +91,11 @@ static int str2state(char *buf)
91 91
 
92 92
 static int usvstate_update(int state, struct usvdev_status *status)
93 93
 {
94
-	static int old_state = -1;
94
+	static int old_state;
95 95
 
96
-	if (status == NULL) {
97
-		if (state != old_state)
98
-			log_print(LOG_INFO, "usv state forced to: %s", state2str(state));
96
+	if (status != NULL)
97
+		state = status->state;
99 98
 
100
-		old_state = state;
101
-		return state;
102
-	}
103
-
104
-	state = status->state;
105 99
 	if (state == old_state)
106 100
 		return state;
107 101
 
@@ -109,20 +103,24 @@ static int usvstate_update(int state, struct usvdev_status *status)
109 103
 
110 104
 	if (mail_to != NULL) {
111 105
 		FILE *mail = popen(SENDMAIL, "w");
112
-		if (mail == NULL) {
106
+		if (mail != NULL) {
113 107
 			fprintf(mail, "From: %s\n", mail_from);
114 108
 			fprintf(mail, "To: %s\n", mail_to);
115 109
 			fprintf(mail, "Subject: alix-usvd state change: %s => %s\n\n",
116 110
 				state2str(old_state), state2str(state));
117 111
 
118
-			fprintf(mail, "Current USV status:\n");
119
-			fprintf(mail, "Ibat:  %1.3lf mA\nUbat: %2.3lf  V\nUin : %2.3lf  V\n\n",
120
-				status->ibat / 1000.0, status->ubat / 1000.0, status->uin / 1000.0);
112
+			if (status != NULL) {
113
+				fprintf(mail, "Current USV status:\n");
114
+				fprintf(mail, "Ibat:  %1.3lf mA\nUbat: %2.3lf  V\nUin : %2.3lf  V\n\n",
115
+					status->ibat / 1000.0, status->ubat / 1000.0, status->uin / 1000.0);
116
+			}
121 117
 
122 118
 			fprintf(mail, "Faithfully yours, etc.\n");
123 119
 			fclose(mail);
124 120
 		}
125 121
 	}
122
+
123
+	old_state = state;
126 124
 	return state;
127 125
 }
128 126
 
@@ -149,7 +147,7 @@ static int unix_read_cb(int fd, void *privdata)
149 147
 
150 148
 		int len = snprintf(buf, sizeof(buf), "%s:%d:%d:%d",
151 149
 					state2str(status.state),
152
-					(signed)status.ibat, status.ubat, status.uin);
150
+					(short)status.ibat, status.ubat, status.uin);
153 151
 		write(fd, buf, len);
154 152
 	}
155 153
 

Loading…
Cancel
Save